Cataclysm BN
item Class Reference

#include <item.h>

Inheritance diagram for item:
visitable< item >

Classes

class  craft_data
 Data for items that represent in-progress crafts. More...
 
struct  default_charges_tag
 Suppress randomization and always start with default quantity of charges. More...
 
struct  solitary_tag
 Default (or randomized) charges except if counted by charges then only one charge. More...
 
struct  sound_data
 

Public Types

using FlagsSetType = cata::flat_set< std::string >
 
using archive_type_tag = io::object_archive_tag
 

Public Member Functions

 item ()
 
 item (item &&)
 
 item (const item &)
 
itemoperator= (item &&)
 
itemoperator= (const item &)
 
 item (const itype_id &id, time_point turn=calendar::turn, int qty=-1)
 
 item (const itype *type, time_point turn=calendar::turn, int qty=-1)
 
 item (const itype_id &id, time_point turn, default_charges_tag)
 
 item (const itype *type, time_point turn, default_charges_tag)
 
 item (const itype_id &id, time_point turn, solitary_tag)
 
 item (const itype *type, time_point turn, solitary_tag)
 
 item (const recipe *rec, int qty, std::list< item > items, std::vector< item_comp > selections)
 For constructing in-progress crafts. More...
 
template<typename... Args>
 item (const std::string &itype, Args &&... args)
 
 ~item ()
 
safe_reference< itemget_safe_reference ()
 Return a pointer-like type that's automatically invalidated if this item is destroyed or assigned-to. More...
 
itemconvert (const itype_id &new_type)
 Filter converting this instance to another type preserving all other aspects. More...
 
itemdeactivate (const Character *ch=nullptr, bool alert=true)
 Filter converting this instance to the inactive type If the item is either inactive or cannot be deactivated is a no-op. More...
 
itemactivate ()
 Filter converting instance to active state. More...
 
units::energy mod_energy (const units::energy &qty)
 Add or remove energy from a battery. More...
 
itemammo_set (const itype_id &ammo, int qty=-1)
 Filter setting the ammo for this instance Any existing ammo is removed. More...
 
itemammo_unset ()
 Filter removing all ammo from this instance If the item is neither a tool, gun nor magazine is a no-op For items reloading using magazines any empty magazine remains present. More...
 
itemset_damage (int qty)
 Filter setting damage constrained by min_damage and max_damage. More...
 
item split (int qty)
 Splits a count-by-charges item always leaving source item with minimum of 1 charge. More...
 
const mtypeget_mtype () const
 
void set_mtype (const mtype *m)
 Sets the monster type associated with this item (corpse). More...
 
bool is_corpse () const
 Whether this is a corpse item. More...
 
bool can_revive () const
 Whether this is a corpse that can be revived. More...
 
bool ready_to_revive (const tripoint &pos) const
 Whether this corpse should revive now. More...
 
bool is_money () const
 
nc_color color () const
 Returns the default color of the item (e.g. More...
 
nc_color color_in_inventory () const
 Returns the color of the item depending on usefulness for the player character, e.g. More...
 
nc_color color_in_inventory (const player &p) const
 Returns the color of the item depending on usefulness for the passed player, e.g. More...
 
std::string tname (unsigned int quantity=1, bool with_prefix=true, unsigned int truncate=0) const
 Return the (translated) item name. More...
 
std::string display_money (unsigned int quantity, unsigned int total, const std::optional< unsigned int > &selected=std::nullopt) const
 
std::string display_name (unsigned int quantity=1) const
 Returns the item name and the charges or contained charges (if the item can have charges at all). More...
 
std::vector< iteminfoinfo () const
 Return all the information about the item and its type as a vector. More...
 
std::vector< iteminfoinfo (int batch) const
 
std::vector< iteminfoinfo (const iteminfo_query &parts, int batch, temperature_flag temperature) const
 
std::vector< iteminfoinfo (temperature_flag temperature) const
 
std::string info_string () const
 As info, but as a string rather than a vector of properties. More...
 
std::string info_string (const iteminfo_query &parts, int batch=1, temperature_flag temperature=temperature_flag::TEMP_NORMAL) const
 
void basic_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void med_info (const item *med_item, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void food_info (const item *food_item, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug, temperature_flag temperature) const
 
void magazine_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void ammo_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void gun_info (const item *mod, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void gunmod_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void armor_protection_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void armor_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void animal_armor_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void armor_fit_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void book_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void battery_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void container_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void tool_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void component_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void repair_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void disassembly_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void qualities_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void bionic_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void combat_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void contents_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void final_info (std::vector< iteminfo > &info, const iteminfo_query &parts, int batch, bool debug) const
 
float simulate_burn (fire_data &frd) const
 Calculate all burning calculations, but don't actually apply them to item. More...
 
bool burn (fire_data &frd)
 Burns the item. More...
 
const item_categoryget_category () const
 
bool reload (player &u, item_location loc, int qty)
 Reload item using ammo from location returning true if successful. More...
 
template<typename Archive >
void io (Archive &)
 
void serialize (JsonOut &json) const
 
void deserialize (JsonIn &jsin)
 
const std::string & symbol () const
 
int price (bool practical) const
 Returns the monetary value of an item. More...
 
bool display_stacked_with (const item &rhs, bool check_components=false) const
 Whether two items should stack when displayed in a inventory menu. More...
 
bool stacks_with (const item &rhs, bool check_components=false, bool skip_type_check=false) const
 
bool merge_charges (const item &rhs)
 Merge charges of the other item into this item. More...
 
units::mass weight (bool include_contents=true, bool integral=false) const
 
units::volume volume (bool integral=false) const
 Total volume of an item accounting for all contained/integrated items NOTE: Result is rounded up to next nearest milliliter when working with stackable (count_by_charges) items that have fractional volume per charge. More...
 
units::volume base_volume () const
 Simplified, faster volume check for when processing time is important and exact volume is not. More...
 
units::volume corpse_volume (const mtype *corpse) const
 Volume check for corpses, helper for base_volume(). More...
 
int lift_strength () const
 Required strength to be able to successfully lift the item unaided by equipment. More...
 
Melee

The functions here assume the item is used in melee, even if's a gun or not a weapon at all.

Because the functions apply to all types of items, several of the is_* functions here may return true for the same item. This only indicates that it can be used in various ways.

int attack_cost () const
 Base number of moves (Creature::moves) that a single melee attack with this items takes. More...
 
int damage_melee (damage_type dt) const
 Damage of given type caused when this item is used as melee weapon. More...
 
damage_instance base_damage_melee () const
 All damage types this item deals when used in melee (no skill modifiers etc. More...
 
damage_instance base_damage_thrown () const
 All damage types this item deals when thrown (no skill modifiers etc. More...
 
double effective_dps (const player &guy, const monster &mon) const
 Calculate the item's effective damage per second past armor when wielded by a character against a monster. More...
 
std::map< std::string, double > dps (bool for_display, bool for_calc, const player &guy) const
 calculate effective dps against a stock set of monsters. More...
 
std::map< std::string, double > dps (bool for_display, bool for_calc) const
 
double average_dps (const player &guy) const
 return the average dps of the weapon against evaluation monsters More...
 
double ideal_ranged_dps (const Character &who, gun_mode &mode) const
 
bool is_two_handed (const Character &guy) const
 Whether the character needs both hands to wield this item. More...
 
bool is_melee (damage_type dt) const
 Is this item an effective melee weapon for the given damage type? More...
 
bool is_melee () const
 Is this item an effective melee weapon for any damage type? More...
 
skill_id melee_skill () const
 The most relevant skill used with this melee weapon. More...
 
int reach_range (const Character &guy) const
 Max range of melee attack this weapon can be used for. More...
 
void set_countdown (int num_turns)
 Sets time until activation for an item that will self-activate in the future. More...
 
bool use_charges (const itype_id &what, int &qty, std::list< item > &used, const tripoint &pos, const std::function< bool(const item &)> &filter=return_true< item >)
 Consumes specified charges (or fewer) from this and any contained items. More...
 
bool on_drop (const tripoint &pos)
 Invokes item type's itype::drop_action. More...
 
bool on_drop (const tripoint &pos, map &map)
 Invokes item type's itype::drop_action. More...
 
bool use_amount (const itype_id &it, int &quantity, std::list< item > &used, const std::function< bool(const item &)> &filter=return_true< item >)
 Consume a specific amount of items of a specific type. More...
 
bool allow_crafting_component () const
 Permits filthy components, should only be used as a helper in creating filters. More...
 
Containers

Containers come in two flavors:

bool is_container () const
 Whether this is container. More...
 
bool is_watertight_container () const
 Whether this is a container which can be used to store liquids. More...
 
bool is_container_empty () const
 Whether this item has no contents at all. More...
 
bool is_non_resealable_container () const
 Whether removing this item's contents will permanently alter it. More...
 
bool is_container_full (bool allow_bucket=false) const
 Whether this item has no more free capacity for its current content. More...
 
void fill_with (item &liquid, int amount=INFINITE_CHARGES)
 Fill item with liquid up to its capacity. More...
 
int get_remaining_capacity_for_liquid (const item &liquid, bool allow_bucket=false, std::string *err=nullptr) const
 How much more of this liquid (in charges) can be put in this container. More...
 
int get_remaining_capacity_for_liquid (const item &liquid, const Character &p, std::string *err=nullptr) const
 
units::volume get_container_capacity () const
 It returns the total capacity (volume) of the container for liquids. More...
 
units::volume get_total_capacity () const
 It returns the maximum volume of any contents, including liquids, ammo, magazines, weapons, etc. More...
 
void put_in (const item &payload)
 Puts the given item into this one, no checks are performed. More...
 
item in_its_container () const
 Returns this item into its default container. More...
 
item in_container (const itype_id &container_type) const
 
bool item_has_uses_recursive () const
 
bool is_funnel_container (units::volume &bigger_than) const
 Funnel related functions. More...
 
void add_rain_to_container (bool acid, int charges=1)
 Add charge(s) of rain to given container, possibly contaminating it. More...
 
int get_quality (const quality_id &id) const
 
std::map< quality_id, int > get_qualities () const
 
bool count_by_charges () const
 
int count () const
 If count_by_charges(), returns charges, otherwise 1. More...
 
bool craft_has_charges ()
 
void mod_charges (int mod)
 Modify the charges of this item, only use for items counted by charges! The item must have enough charges for this (>= quantity) and be counted by charges. More...
 
bool actualize_rot (const tripoint &pnt, temperature_flag temperature, const weather_manager &weather)
 Whether the item has to be removed as it has rotten away completely. More...
 
time_duration calc_rot (time_point time, int temp) const
 Returns rot of the item since last rot calculation. More...
 
time_duration minimum_freshness_duration (temperature_flag temperature) const
 Time that this item is guaranteed to stay fresh. More...
 
void mod_last_rot_check (time_duration processing_duration)
 This is part of a workaround so that items don't rot away to nothing if the smoking rack is outside the reality bubble. More...
 
bool process_rot (const tripoint &pos)
 Update temperature for things like food Update rot for things that perish All items that rot also have temperature. More...
 
bool process_rot (bool seals, const tripoint &pos, player *carrier, temperature_flag flag, const weather_manager &weather_generator)
 
int get_comestible_fun () const
 
bool goes_bad () const
 whether an item is perishable (can rot) More...
 
bool goes_bad_after_opening () const
 whether an item is perishable (can rot), even if it is currently in a preserving container More...
 
time_duration get_shelf_life () const
 Get the shelf life of the item. More...
 
double get_relative_rot () const
 Get rot value relative to shelf life (or 0 if item does not spoil) More...
 
void set_relative_rot (double val)
 Set current item rot relative to shelf life (no-op if item does not spoil) More...
 
void set_rot (time_duration val)
 
int spoilage_sort_order () const
 Get time left to rot, ignoring fridge. More...
 
bool is_fresh () const
 an item is fresh if it is capable of rotting but still has a long shelf life remaining More...
 
bool is_going_bad () const
 an item is about to become rotten when shelf life has nearly elapsed More...
 
bool rotten () const
 returns true if item is now rotten after all shelf life has elapsed More...
 
bool has_rotten_away () const
 Whether the item has enough rot that it should get removed. More...
 
time_duration get_rot () const
 
void mod_rot (const time_duration &val)
 
time_duration brewing_time () const
 Time for this item to be fully fermented. More...
 
const std::vector< itype_id > & brewing_results () const
 The results of fermenting this item. More...
 
bool detonate (const tripoint &p, std::vector< item > &drops)
 Detonates the item and adds remains (if any) to drops. More...
 
bool will_explode_in_fire () const
 
Material(s) of the item

Each item is made of one or more materials (material_type).

Materials have properties that affect properties of the item (e.g. resistance against certain damage types).

Corpses inherit the material of the monster type.

const material_typeget_random_material () const
 Get a material reference to a random material that this item is made of. More...
 
const material_typeget_base_material () const
 Get the basic (main) material of this item. More...
 
const std::vector< material_id > & made_of () const
 The ids of all the materials this is made of. More...
 
const std::map< quality_id, int > & quality_of () const
 The ids of all the qualities this contains. More...
 
std::vector< const material_type * > made_of_types () const
 Same as made_of(), but returns the material_type directly. More...
 
bool made_of_any (const std::set< material_id > &mat_idents) const
 Check we are made of at least one of a set (e.g. More...
 
bool only_made_of (const std::set< material_id > &mat_idents) const
 Check we are made of only the materials (e.g. More...
 
bool made_of (const material_id &mat_ident) const
 Check we are made of this material (e.g. More...
 
bool contents_made_of (phase_id phase) const
 If contents nonempty, return true if item phase is same, else false. More...
 
bool made_of (phase_id phase) const
 Are we solid, liquid, gas, plasma? More...
 
std::vector< item_compget_uncraft_components () const
 Returns a list of components used to craft this item or the default components if it wasn't player-crafted. More...
 
bool conductive () const
 Whether the items is conductive. More...
 
bool flammable (int threshold=0) const
 Whether the items is flammable. More...
 
bool reinforceable () const
 Whether the item can be repaired beyond normal health. More...
 
int acid_resist (bool to_self=false, int base_env_resist=0) const
 Resistance against different damage types (damage_type). More...
 
int fire_resist (bool to_self=false, int base_env_resist=0) const
 
int bash_resist (bool to_self=false) const
 
int cut_resist (bool to_self=false) const
 
int stab_resist (bool to_self=false) const
 
int bullet_resist (bool to_self=false) const
 
void mitigate_damage (damage_unit &du) const
 Assuming that specified du hit the armor, reduce du based on the item's resistance to the damage type. More...
 
int damage_resist (damage_type dt, bool to_self=false) const
 Resistance provided by this item against damage type given by an enum. More...
 
int chip_resistance (bool worst=false) const
 Returns resistance to being damaged by attack against the item itself. More...
 
int damage () const
 How much damage has the item sustained? More...
 
int damage_level (int max) const
 Scale item damage to the given number of levels. More...
 
int min_damage () const
 Minimum amount of damage to an item (state of maximum repair) More...
 
int max_damage () const
 Maximum amount of damage to an item (state before destroyed) More...
 
float get_relative_health () const
 Relative item health. More...
 
bool mod_damage (int qty, damage_type dt)
 Apply damage to const itemrained by min_damage and max_damage. More...
 
bool mod_damage (int qty)
 same as other mod_damage, but uses DT_NULL as damage type. More...
 
bool inc_damage (damage_type dt)
 Increment item damage by itype::damage_scale constrained by max_damage. More...
 
bool inc_damage ()
 same as other inc_damage, but uses DT_NULL as damage type. More...
 
nc_color damage_color () const
 Provide color for UI display dependent upon current item damage level. More...
 
std::string damage_symbol () const
 Provide prefix symbol for UI display dependent upon current item damage level. More...
 
std::string durability_indicator (bool include_intact=false) const
 Provides a prefix for the durability state of the item. More...
 
const std::set< itype_id > & repaired_with () const
 If possible to repair this item what tools could potentially be used for this purpose? More...
 
bool already_used_by_player (const player &p) const
 Check whether the item has been marked (by calling mark_as_used_by_player) as used by this specific player. More...
 
void mark_as_used_by_player (const player &p)
 Marks the item as being used by this specific player, it remains unmarked for other players. More...
 
bool is_filthy () const
 Marks the item as filthy, so characters with squeamish trait can't wear it. More...
 
bool process (player *carrier, const tripoint &pos, bool activate, temperature_flag flag=temperature_flag::TEMP_NORMAL)
 This is called once each turn. More...
 
bool process (player *carrier, const tripoint &pos, bool activate, temperature_flag flag, const weather_manager &weather_generator)
 
std::optional< tripointget_cable_target (Character *p, const tripoint &pos) const
 Gets the point (vehicle tile) the cable is connected to. More...
 
void reset_cable (player *p)
 Helper to bring a cable back to its initial state. More...
 
bool needs_processing () const
 Whether the item should be processed (by calling process). More...
 
int processing_speed () const
 The rate at which an item should be processed, in number of turns between updates. More...
 
void process_artifact (player *carrier, const tripoint &pos)
 Process and apply artifact effects. More...
 
void process_relic (Character &carrier)
 
bool destroyed_at_zero_charges () const
 
bool is_null () const
 
bool is_comestible () const
 
bool is_food () const
 
bool is_food_container () const
 
bool is_med_container () const
 
bool is_ammo_container () const
 
bool is_medication () const
 
bool is_bionic () const
 
bool is_magazine () const
 
bool is_battery () const
 
bool is_ammo_belt () const
 
bool is_bandolier () const
 
bool is_holster () const
 
bool is_ammo () const
 
bool is_pet_armor (bool on_pet=false) const
 
bool is_armor () const
 
bool is_book () const
 
bool is_map () const
 
bool is_salvageable () const
 
bool is_craft () const
 
bool is_deployable () const
 
bool is_tool () const
 
bool is_transformable () const
 
bool is_artifact () const
 
bool is_relic () const
 
bool is_bucket () const
 
bool is_bucket_nonempty () const
 
bool is_brewable () const
 
bool is_engine () const
 
bool is_wheel () const
 
bool is_fuel () const
 
bool is_toolmod () const
 
bool is_faulty () const
 
bool is_irremovable () const
 
bool is_unarmed_weapon () const
 
itemget_food ()
 
const itemget_food () const
 
int wind_resist () const
 How resistant clothes made of this material are to wind (0-100) More...
 
std::set< fault_idfaults_potential () const
 What faults can potentially occur with this item? More...
 
int wheel_area () const
 Returns the total area of this wheel or 0 if it isn't one. More...
 
float fuel_energy () const
 Returns energy of one charge of this item as fuel for an engine. More...
 
std::string fuel_pump_terrain () const
 Returns the string of the id of the terrain that pumps this fuel, if any. More...
 
bool has_explosion_data () const
 
struct fuel_explosion get_explosion_data ()
 
bool can_contain (const item &it) const
 Can this item have given item/itype as content? More...
 
bool can_contain (const itype &tp) const
 
bool is_reloadable () const
 Is it ever possible to reload this item? Only the base item is considered with any mods ignored. More...
 
bool can_reload_with (const ammotype &ammo) const
 Returns true if this item can be reloaded with specified ammo type, ignoring currently loaded ammo. More...
 
bool can_reload_with (const itype_id &ammo) const
 Returns true if this item can be reloaded with specified ammo item, ignoring currently loaded ammo. More...
 
bool is_reloadable_with (const itype_id &ammo) const
 Returns true if this item can be reloaded with specified ammo type at this moment. More...
 
bool can_unload_liquid () const
 Returns true if not empty if it's liquid, it's not currently frozen in resealable container. More...
 
bool is_dangerous () const
 
bool is_tainted () const
 Is item derived from a zombie? More...
 
bool is_soft () const
 Is this item flexible enough to be worn on body parts like antlers? More...
 
bool has_effect_when_wielded (art_effect_passive effect) const
 Does the item provide the artifact effect when it is wielded? More...
 
bool has_effect_when_worn (art_effect_passive effect) const
 Does the item provide the artifact effect when it is worn? More...
 
bool has_effect_when_carried (art_effect_passive effect) const
 Does the item provide the artifact effect when it is carried? More...
 
void set_snippet (const snippet_id &id)
 Set the snippet text (description) of this specific item, using the snippet library. More...
 
bool operator< (const item &other) const
 
std::string components_to_string () const
 List of all components in printable form, empty if this item has no components. More...
 
uint64_t make_component_hash () const
 Creates a hash from the itype_ids of this item's components. More...
 
const itype_idtypeId () const
 return the unique identifier of the items underlying type More...
 
const itemget_contained () const
 Return a contained item (if any and only one). More...
 
bool spill_contents (Character &c)
 Unloads the item's contents. More...
 
bool spill_contents (const tripoint &pos)
 Unloads the item's contents. More...
 
bool can_holster (const item &obj, bool ignore=false) const
 Checks if item is a holster and currently capable of storing obj. More...
 
void on_wear (Character &p)
 Callback when a character starts wearing the item. More...
 
void on_takeoff (Character &p)
 Callback when a character takes off an item. More...
 
void on_wield (player &p, int mv=0)
 Callback when a player starts wielding the item. More...
 
void on_pickup (Character &p)
 Callback when a player starts carrying the item. More...
 
void on_contents_changed ()
 Callback when contents of the item are affected in any way other than just processing. More...
 
void on_damage (int qty, damage_type dt)
 Callback immediately before an item is damaged. More...
 
std::vector< trait_idmutations_from_wearing (const Character &guy) const
 
std::string type_name (unsigned int quantity=1) const
 Name of the item type (not the item), with proper plural. More...
 
int charges_per_volume (const units::volume &vol) const
 Number of (charges of) this item that fit into the given volume. More...
 
Item variables

Item variables can be used to store any value in the item.

The storage is persistent, it remains through saving & loading, it is copied when the item is moved etc. Each item variable is referred to by its name, so make sure you use a name that is not already used somewhere. You can directly store integer, floating point and string values. Data of other types must be converted to one of those to be stored. The set_var functions override the existing value. The get_var function return the value (if the variable exists), or the default value otherwise. The type of the default value determines which get_var function is used. All numeric values are returned as doubles and may be cast to the desired type. int v = itm.get_var("v", 0); // v will be an int double d = itm.get_var("v", 0.0); // d will be a double std::string s = itm.get_var("v", ""); // s will be a std::string // no default means empty string as default: auto n = itm.get_var("v"); // v will be a std::string

void set_var (const std::string &name, int value)
 
void set_var (const std::string &name, long long value)
 
void set_var (const std::string &name, long value)
 
void set_var (const std::string &name, double value)
 
double get_var (const std::string &name, double default_value) const
 
void set_var (const std::string &name, const tripoint &value)
 
tripoint get_var (const std::string &name, const tripoint &default_value) const
 
void set_var (const std::string &name, const std::string &value)
 
std::string get_var (const std::string &name, const std::string &default_value) const
 
std::string get_var (const std::string &name) const
 Get the variable, if it does not exists, returns an empty string. More...
 
bool has_var (const std::string &name) const
 Whether the variable is defined at all. More...
 
void erase_var (const std::string &name)
 Erase the value of the given variable. More...
 
void clear_vars ()
 Removes all item variables. More...
 
Item flags

If you use any new flags, add them to flags.json, add a comment to doc/JSON_FLAGS.md and make sure your new flag does not conflict with any existing flag.

Item flags are taken from the item type (itype::item_tags), but also from the item itself (item_tags). The item has the flag if it appears in either set.

Gun mods that are attached to guns also contribute their flags to the gun item.

bool has_flag (const std::string &flag) const
 
bool has_flag (const flag_str_id &flag) const
 
template<typename Container , typename T = std::decay_t<decltype( *std::declval<const Container &>().begin() )>>
bool has_any_flag (const Container &flags) const
 
bool has_own_flag (const std::string &flag) const
 Checks whether item itself has given flag (doesn't check item type or gunmods). More...
 
const FlagsSetTypeget_flags () const
 returs read-only set of flags of this item (not including flags from item type or gunmods) More...
 
itemset_flag (const std::string &flag)
 Idempotent filter setting an item specific flag. More...
 
itemunset_flag (const std::string &flag)
 Idempotent filter removing an item specific flag. More...
 
itemset_flag_recursive (const std::string &flag)
 Idempotent filter recursively setting an item specific flag on this item and its components. More...
 
void unset_flags ()
 Removes all item specific flags. More...
 
bool has_fault (const fault_id &fault) const
 Does this item have the specified fault. More...
 
Item properties

Properties are specific to an item type so unlike flags the meaning of a property may not be the same for two different item types.

Each item type can have multiple properties however duplicate property names are not permitted.

bool has_property (const std::string &prop) const
 
std::string get_property_string (const std::string &prop, const std::string &def="") const
 Get typed property for item. More...
 
int64_t get_property_int64_t (const std::string &prop, int64_t def=0) const
 
Light emitting items

Items can emit light either through the definition of their type (itype::light_emission) or through an item specific light data (light).

bool getlight (float &luminance, units::angle &width, units::angle &direction) const
 Directional light emission of the item. More...
 
int getlight_emit () const
 How much light (see lightmap.cpp) the item emits (it's assumed to be circular). More...
 
bool is_emissive () const
 Whether the item emits any light at all. More...
 
Seed data.
bool is_seed () const
 Whether this is actually a seed, the seed functions won't be of much use for non-seeds. More...
 
time_duration get_plant_epoch () const
 Time it takes to grow from one stage to another. More...
 
std::string get_plant_name () const
 The name of the plant as it appears in the various informational menus. More...
 
Armor related functions.

The functions here refer to values from islot_armor.

They only apply to armor items, those items can be worn. The functions are safe to call for any item, for non-armor they return a default value.

bool covers (body_part bp) const
 Whether this item (when worn) covers the given body part. More...
 
bool covers (const bodypart_id &bp) const
 
body_part_set get_covered_body_parts () const
 Bitset of all covered body parts. More...
 
body_part_set get_covered_body_parts (side s) const
 Bitset of all covered body parts, from a specific side. More...
 
bool is_sided () const
 Returns true if item is armor and can be worn on different sides of the body. More...
 
side get_side () const
 Returns side item currently worn on. More...
 
bool set_side (side s)
 Change the side on which the item is worn. More...
 
bool swap_side ()
 Swap the side on which the item is worn. More...
 
int get_warmth () const
 Returns the warmth value that this item has when worn. More...
 
int get_thickness () const
 Returns the islot_armor::thickness value, or 0 for non-armor. More...
 
layer_level get_layer () const
 Returns clothing layer for item. More...
 
int get_coverage () const
 Returns the relative coverage that this item has when worn. More...
 
int get_encumber_when_containing (const Character &, const units::volume &contents_volume) const
 Returns the encumbrance value that this item has when worn by given player, when containing a particular volume of contents. More...
 
int get_encumber (const Character &) const
 Returns the encumbrance value that this item has when worn by given player. More...
 
units::volume get_storage () const
 Returns the storage amount (islot_armor::storage) that this item provides when worn. More...
 
float get_weight_capacity_modifier () const
 Returns the weight capacity modifier (islot_armor::weight_capacity_modifier) that this item provides when worn. More...
 
units::mass get_weight_capacity_bonus () const
 Returns the weight capacity bonus (islot_armor::weight_capacity_modifier) that this item provides when worn. More...
 
int get_env_resist (int override_base_resist=0) const
 Returns the resistance to environmental effects (islot_armor::env_resist) that this item provides when worn. More...
 
int get_base_env_resist_w_filter () const
 Returns the base resistance to environmental effects if an item (for example a gas mask) requires a gas filter to operate and this filter is installed. More...
 
bool is_power_armor () const
 Whether this is a power armor item. More...
 
const islot_armorfind_armor_data () const
 If this is an armor item, return its armor data. More...
 
bool is_worn_only_with (const item &it) const
 Returns true whether this item can be worn only when. More...
 
Pet armor related functions.

The functions here refer to values from islot_pet_armor.

They only apply to pet armor items, those items can be worn by pets. The functions are safe to call for any item, for non-pet armor they return a default value.

units::volume get_pet_armor_max_vol () const
 
units::volume get_pet_armor_min_vol () const
 
bodytype_id get_pet_armor_bodytype () const
 
Books

Book specific functions, apply to items that are books.

int get_chapters () const
 How many chapters the book has (if any). More...
 
int get_remaining_chapters (const Character &ch) const
 Get the number of unread chapters. More...
 
void mark_chapter_as_read (const Character &ch)
 Mark one chapter of the book as read by the given player. More...
 
std::vector< std::pair< const recipe *, int > > get_available_recipes (const player &u) const
 Enumerates recipes available from this book and the skill level required to use them. More...
 
Martial art techniques

See martialarts.h for further info.

bool has_technique (const matec_id &tech) const
 Whether the item supports a specific martial art technique (either through its type, or through its individual techniques). More...
 
std::set< matec_idget_techniques () const
 Returns all the martial art techniques that this items supports. More...
 
void add_technique (const matec_id &tech)
 Add the given technique to the item specific techniques. More...
 
std::vector< item * > toolmods ()
 Returns all toolmods currently attached to this item (always empty if item not a tool) More...
 
std::vector< const item * > toolmods () const
 
Gun and gunmod functions

Gun and gun mod functions.

Anything stated to apply to guns, applies to auxiliary gunmods as well (they are some kind of gun). Non-guns are items that are neither gun nor auxiliary gunmod.

bool is_gunmod () const
 
bool is_gun () const
 Can this item be used to perform a ranged attack? More...
 
units::energy energy_remaining () const
 Quantity of energy currently loaded in tool or battery. More...
 
int ammo_remaining () const
 Quantity of ammunition currently loaded in tool, gun or auxiliary gunmod. More...
 
int ammo_capacity () const
 Maximum quantity of ammunition loadable for tool, gun or auxiliary gunmod. More...
 
int ammo_capacity (bool potential_capacity) const
 
int ammo_required () const
 Quantity of ammunition consumed per usage of tool or with each shot of gun. More...
 
bool ammo_sufficient (int qty=1) const
 Check if sufficient ammo is loaded for given number of uses. More...
 
int ammo_consume (int qty, const tripoint &pos)
 Consume ammo (if available) and return the amount of ammo that was consumed. More...
 
const itypeammo_data () const
 Specific ammo data, returns nullptr if item is neither ammo nor loaded with any. More...
 
itype_id ammo_current () const
 Specific ammo type, returns "null" if item is neither ammo nor loaded with any. More...
 
const std::set< ammotype > & ammo_types (bool conversion=true) const
 Set of ammo types (ammunition_type) used by item. More...
 
ammotype ammo_type () const
 Ammo type of an ammo item. More...
 
itype_id ammo_default (bool conversion=true) const
 Get default ammo used by item or a null id if item does not have a default ammo type. More...
 
itype_id common_ammo_default (bool conversion=true) const
 Get default ammo for the first ammotype common to an item and its current magazine or "NULL" if none exists. More...
 
std::set< ammo_effect_str_idammo_effects (bool with_ammo=true) const
 Get ammo effects for item optionally inclusive of any resulting from the loaded ammo. More...
 
std::string ammo_sort_name () const
 
int casings_count () const
 How many spent casings are contained within this item? More...
 
void casings_handle (const std::function< bool(item &)> &func)
 Apply predicate to each contained spent casing removing it if predicate returns true. More...
 
bool magazine_integral () const
 Does item have an integral magazine (as opposed to allowing detachable magazines) More...
 
itype_id magazine_default (bool conversion=true) const
 Get the default magazine type (if any) for the current effective ammo type. More...
 
std::set< itype_idmagazine_compatible (bool conversion=true) const
 Get compatible magazines (if any) for this item. More...
 
itemmagazine_current ()
 Currently loaded magazine (if any) More...
 
const itemmagazine_current () const
 
std::vector< item * > gunmods ()
 Returns all gunmods currently attached to this item (always empty if item not a gun) More...
 
std::vector< const item * > gunmods () const
 
itemgunmod_find (const itype_id &mod)
 Get first attached gunmod matching type or nullptr if no such mod or item is not a gun. More...
 
const itemgunmod_find (const itype_id &mod) const
 
ret_val< bool > is_gunmod_compatible (const item &mod) const
 
std::map< gun_mode_id, gun_modegun_all_modes () const
 Get all possible modes for this gun inclusive of any attached gunmods. More...
 
gun_mode gun_get_mode (const gun_mode_id &mode) const
 Check if gun supports a specific mode returning an invalid/empty mode if not. More...
 
gun_mode gun_current_mode () const
 Get the current mode for this gun (or an invalid mode if item is not a gun) More...
 
gun_mode_id gun_get_mode_id () const
 Get id of mode a gun is currently set to, e.g. More...
 
bool gun_set_mode (const gun_mode_id &mode)
 Try to set the mode for a gun, returning false if no such mode is possible. More...
 
void gun_cycle_mode ()
 Switch to the next available firing mode. More...
 
int sight_dispersion () const
 Get lowest dispersion of either integral or any attached sights. More...
 
sound_data gun_noise (bool burst=false) const
 Returns the sound of the gun being fired. More...
 
bool is_silent () const
 Whether this is a (nearly) silent gun (a tiny bit of sound is allowed). More...
 
int gun_range (const player *p) const
 The weapons range in map squares. More...
 
int gun_range (bool with_ammo=true) const
 Summed range value of a gun, including values from mods. More...
 
double gun_recoil_multiplier (bool bipod=false) const
 Get multiplier on recoil considering handling and attached gunmods. More...
 
int gun_recoil (bool bipod=false) const
 Get effective recoil considering handling, loaded ammo and effects of attached gunmods. More...
 
damage_instance gun_damage (bool with_ammo=true) const
 Summed ranged damage, armor piercing, and multipliers for both, of a gun, including values from mods. More...
 
int gun_dispersion (bool with_ammo=true, bool with_scaling=true) const
 Summed dispersion of a gun, including values from mods. More...
 
skill_id gun_skill () const
 The skill used to operate the gun. More...
 
std::map< gunmod_location, int > get_mod_locations () const
 Get mod locations, including those added by other mods. More...
 
int get_free_mod_locations (const gunmod_location &location) const
 Number of mods that can still be installed into the given mod location, for non-guns it always returns 0. More...
 
bool is_firearm () const
 Does it require gunsmithing tools to repair. More...
 
int get_reload_time () const
 Returns the reload time of the gun. More...
 
Vehicle parts
int engine_displacement () const
 for combustion engines the displacement (cc) More...
 
- Public Member Functions inherited from visitable< item >
VisitResponse visit_items (const std::function< VisitResponse(item *, item *)> &func)
 Traverses this object and any child items contained using a visitor pattern. More...
 
VisitResponse visit_items (const std::function< VisitResponse(const item *, const item *)> &func) const
 
VisitResponse visit_items (const std::function< VisitResponse(item *)> &func)
 Lightweight version which provides only the current node. More...
 
VisitResponse visit_items (const std::function< VisitResponse(const item *)> &func) const
 
itemfind_parent (const item &it)
 Determine the immediate parent container (if any) for an item. More...
 
const itemfind_parent (const item &it) const
 
std::vector< item * > parents (const item &it)
 Returns vector of parent containers (if any) starting with the innermost. More...
 
std::vector< const item * > parents (const item &it) const
 
bool has_item (const item &it) const
 Returns true if this visitable instance contains the item. More...
 
bool has_item_with (const std::function< bool(const item &)> &filter) const
 Returns true if any item (including those within a container) matches the filter. More...
 
bool has_quality (const quality_id &qual, int level=1, int qty=1) const
 Returns true if instance has amount (or more) items of at least quality level. More...
 
int max_quality (const quality_id &qual) const
 Return maximum tool quality level provided by instance or INT_MIN if not found. More...
 
int charges_of (const itype_id &what, int limit=INT_MAX, const std::function< bool(const item &)> &filter=return_true< item >, std::function< void(int)> visitor=nullptr) const
 Count maximum available charges from this instance and any contained items. More...
 
int amount_of (const itype_id &what, bool pseudo=true, int limit=INT_MAX, const std::function< bool(const item &)> &filter=return_true< item >) const
 Count items matching id including both this instance and any contained items. More...
 
bool has_amount (const itype_id &what, int qty, bool pseudo=true, const std::function< bool(const item &)> &filter=return_true< item >) const
 Check instance provides at least qty of an item (. More...
 
std::vector< item * > items_with (const std::function< bool(const item &)> &filter)
 Returns all items (including those within a container) matching the filter. More...
 
std::vector< const item * > items_with (const std::function< bool(const item &)> &filter) const
 
std::list< itemremove_items_with (const std::function< bool(const item &)> &filter, int count=INT_MAX)
 Removes items contained by this instance which match the filter. More...
 
item remove_item (item &it)
 Removes and returns the item which must be contained by this instance. More...
 

Static Public Member Functions

static item make_corpse (const mtype_id &mt=string_id< mtype >::NULL_ID(), time_point turn=calendar::turn, const std::string &name="", int upgrade_time=-1)
 Make a corpse of the given monster type. More...
 

Bionics / CBMs

Functions specific to CBMs

enum class  sizing {
  human_sized_human_char = 0 , big_sized_human_char , small_sized_human_char , big_sized_big_char ,
  human_sized_big_char , small_sized_big_char , small_sized_small_char , human_sized_small_char ,
  big_sized_small_char , not_wearable
}
 
static const int INFINITE_CHARGES = INT_MAX
 
const itypetype
 
item_contents contents
 
std::list< itemcomponents
 
std::set< fault_idfaults
 What faults (if any) currently apply to this item. More...
 
FlagsSetType item_tags
 
int charges
 
units::energy energy
 
int recipe_charges = 1
 
int burnt = 0
 
int poison = 0
 
int frequency = 0
 
snippet_id snip_id = snippet_id::NULL_ID()
 
int irradiation = 0
 
int item_counter = 0
 
int mission_id = -1
 
int player_id = -1
 
bool encumbrance_update_ = false
 
char invlet = 0
 
bool active = false
 
safe_reference< Characteractivated_by
 
bool is_favorite = false
 
pimpl< item_drop_tokendrop_token
 Two items are dropped in same "batch" if they have identical drop tokens Ideally, this would be stored outside item class. More...
 
safe_reference_anchor anchor
 
const itypecurammo = nullptr
 
std::map< std::string, std::string > item_vars
 
const mtypecorpse = nullptr
 
std::string corpse_name
 
std::set< matec_idtechniques
 
cata::value_ptr< craft_datacraft_data_
 
cata::value_ptr< relicrelic_data
 
time_duration rot = 0_turns
 Accumulated rot, expressed as time the item has been in standard temperature. More...
 
time_point last_rot_check = calendar::turn_zero
 Time when the rot calculation was last performed. More...
 
time_point bday
 The time the item was created. More...
 
faction_id owner = faction_id::NULL_ID()
 
faction_id old_owner = faction_id::NULL_ID()
 
int damage_ = 0
 
light_emission light = nolight
 
bool is_upgrade () const
 Whether the CBM is an upgrade to another bionic module. More...
 
bool has_use () const
 Returns true if the item has any use function. More...
 
const use_functionget_use (const std::string &use_name) const
 Returns the pointer to use_function with name use_name assigned to the type of this item or any of its contents. More...
 
itemget_usable_item (const std::string &use_name)
 Checks this item and its contents (recursively) for types that have use_function with type use_name. More...
 
int units_remaining (const Character &ch, int limit=INT_MAX) const
 How many units (ammo or charges) are remaining? More...
 
bool units_sufficient (const Character &ch, int qty=-1) const
 Check if item has sufficient units (ammo or charges) remaining. More...
 
std::string get_corpse_name ()
 Returns name of deceased being if it had any or empty string if not. More...
 
bool has_label () const
 Returns true if item has "item_label" itemvar. More...
 
std::string label (unsigned int quantity=0) const
 Returns label from "item_label" itemvar and quantity. More...
 
bool has_infinite_charges () const
 
skill_id contextualize_skill (const skill_id &id) const
 Puts the skill in context of the item. More...
 
bool release_monster (const tripoint &target, int radius=0)
 
int contain_monster (const tripoint &target)
 
time_duration age () const
 
void set_age (const time_duration &age)
 
void legacy_fast_forward_time ()
 
time_point birthday () const
 
void set_birthday (const time_point &bday)
 
void handle_pickup_ownership (Character &c)
 
int get_gun_ups_drain () const
 
void validate_ownership () const
 
void set_old_owner (const faction_id &temp_owner)
 
void remove_old_owner () const
 
void set_owner (const faction_id &new_owner)
 
void set_owner (const Character &c)
 
void remove_owner () const
 
faction_id get_owner () const
 
faction_id get_old_owner () const
 
bool is_owned_by (const Character &c, bool available_to_take=false) const
 
bool is_old_owner (const Character &c, bool available_to_take=false) const
 
std::string get_owner_name () const
 
int get_min_str () const
 
const cata::value_ptr< islot_comestible > & get_comestible () const
 
const recipeget_making () const
 Get the stored recipe for in progress crafts. More...
 
int get_next_failure_point () const
 Get the failure point stored in this item. More...
 
void set_next_failure_point (const player &crafter)
 Calculates and sets the next failure point for an in progress craft. More...
 
bool handle_craft_failure (player &crafter)
 Handle failure during crafting. More...
 
requirement_data get_continue_reqs () const
 Returns requirement data representing what is needed to resume work on an in progress craft. More...
 
void inherit_flags (const item &parent, const recipe &making)
 Inherit applicable flags from the given parent item. More...
 
void inherit_flags (const std::list< item > &parents, const recipe &making)
 Inherit applicable flags from the given list of parent items. More...
 
void set_tools_to_continue (bool value)
 
bool has_tools_to_continue () const
 
void set_cached_tool_selections (const std::vector< comp_selection< tool_comp > > &selections)
 
const std::vector< comp_selection< tool_comp > > & get_cached_tool_selections () const
 
const std::vector< enchantment > & get_enchantments () const
 
double bonus_from_enchantments (const Character &owner, double base, enchant_vals::mod value, bool round=false) const
 Calculate bonus from enchantments that affect this item only. More...
 
double bonus_from_enchantments_wielded (double base, enchant_vals::mod value, bool round=false) const
 Calculate bonus from enchantments that affect this item only, assume it's wielded and all enchantments' conditions are satisfied. More...
 
const std::vector< relic_recharge > & get_relic_recharge_scheme () const
 
sizing get_sizing (const Character &, bool) const
 
void set_favorite (bool favorite)
 
bool has_clothing_mod () const
 
float get_clothing_mod_val (clothing_mod_type type) const
 
void update_clothing_mod_val ()
 
static std::string nname (const itype_id &id, unsigned int quantity=1)
 Returns the translated item name for the item with given id. More...
 
static bool count_by_charges (const itype_id &id)
 Whether the item is counted by charges, this is a static wrapper around count_by_charges, that does not need an items instance. More...
 
bool use_amount_internal (const itype_id &it, int &quantity, std::list< item > &used, const std::function< bool(const item &)> &filter=return_true< item >)
 
const use_functionget_use_internal (const std::string &use_name) const
 
bool process_internal (player *carrier, const tripoint &pos, bool activate, bool seals, temperature_flag flag, const weather_manager &weather_generator)
 
bool is_reloadable_helper (const itype_id &ammo, bool now) const
 Helper for checking reloadability. More...
 
bool process_corpse (player *carrier, const tripoint &pos)
 
bool process_wet (player *carrier, const tripoint &pos)
 
bool process_litcig (player *carrier, const tripoint &pos)
 
bool process_extinguish (player *carrier, const tripoint &pos)
 
bool process_fake_smoke (player *carrier, const tripoint &pos)
 
bool process_fake_mill (player *carrier, const tripoint &pos)
 
bool process_cable (player *carrier, const tripoint &pos)
 
bool process_UPS (player *carrier, const tripoint &pos)
 
bool process_blackpowder_fouling (player *carrier)
 
bool process_tool (player *carrier, const tripoint &pos)
 

Additional Inherited Members

Detailed Description

Definition at line 209 of file item.h.

Member Typedef Documentation

◆ archive_type_tag

Definition at line 493 of file item.h.

◆ FlagsSetType

using item::FlagsSetType = cata::flat_set<std::string>

Definition at line 212 of file item.h.

Member Enumeration Documentation

◆ sizing

enum class item::sizing
strong
Enumerator
human_sized_human_char 
big_sized_human_char 
small_sized_human_char 
big_sized_big_char 
human_sized_big_char 
small_sized_big_char 
small_sized_small_char 
human_sized_small_char 
big_sized_small_char 
not_wearable 

Definition at line 2126 of file item.h.

2126 {
2127 human_sized_human_char = 0,
2128 big_sized_human_char,
2129 small_sized_human_char,
2130 big_sized_big_char,
2131 human_sized_big_char,
2132 small_sized_big_char,
2133 small_sized_small_char,
2134 human_sized_small_char,
2135 big_sized_small_char,
2136 not_wearable
2137 };

Constructor & Destructor Documentation

◆ item() [1/11]

item::item ( )

Definition at line 368 of file item.cpp.

369{
370 type = nullitem();
371 charges = 0;
372}
time_point bday
The time the item was created.
Definition: item.h:2227
int charges
Definition: item.h:2199
const itype * type
Definition: item.h:2160
static const itype * nullitem()
Definition: item.cpp:319
const time_point & start_of_cataclysm
Definition: calendar.cpp:33

References charges, nullitem(), and type.

Referenced by add_rain_to_container(), ammo_set(), vehicle_part::deserialize(), io(), item(), and split().

◆ item() [2/11]

item::item ( item &&  )
default

◆ item() [3/11]

item::item ( const item )
default

◆ item() [4/11]

item::item ( const itype_id id,
time_point  turn = calendar::turn,
int  qty = -1 
)
explicit

Definition at line 434 of file item.cpp.

435 : item( & * id, turn, qty ) {}
item()
Definition: item.cpp:368
time_point turn
Definition: calendar.cpp:36

◆ item() [5/11]

item::item ( const itype type,
time_point  turn = calendar::turn,
int  qty = -1 
)
explicit

Definition at line 374 of file item.cpp.

374 : type( type ), bday( turn )
375{
376 corpse = has_flag( flag_CORPSE ) ? &mtype_id::NULL_ID().obj() : nullptr;
378
379 if( qty >= 0 ) {
380 charges = qty;
381 } else {
382 if( type->tool && type->tool->rand_charges.size() > 1 ) {
383 const int charge_roll = rng( 1, type->tool->rand_charges.size() - 1 );
384 charges = rng( type->tool->rand_charges[charge_roll - 1], type->tool->rand_charges[charge_roll] );
385 } else {
387 }
388 }
389
391 itype_id nanofab_recipe = item_group::item_from( item_group_id( "nanofab_recipes" ) ).typeId();
392 set_var( "NANOFAB_ITEM_ID", nanofab_recipe.str() );
393 }
394
395 if( type->gun ) {
396 for( const itype_id &mod : type->gun->built_in_mods ) {
397 item it( mod, turn, qty );
398 it.set_flag( "IRREMOVABLE" );
399 put_in( it );
400 }
401 for( const itype_id &mod : type->gun->default_mods ) {
402 put_in( item( mod, turn, qty ) );
403 }
404
405 } else if( type->magazine ) {
406 if( type->magazine->count > 0 ) {
407 put_in( item( type->magazine->default_ammo, calendar::turn, type->magazine->count ) );
408 }
409
410 } else if( goes_bad() ) {
411 active = true;
413
414 } else if( type->tool ) {
415 if( ammo_remaining() && !ammo_types().empty() ) {
417 }
418 }
419
420 if( ( type->gun || type->tool ) && !magazine_integral() ) {
421 set_var( "magazine_converted", 1 );
422 }
423
424 if( !type->snippet_category.empty() ) {
426 }
427
428 // item always has any relic properties from itype.
429 if( type->relic_data ) {
431 }
432}
units::quantity< V, B > rng(const units::quantity< V, B > &min, const units::quantity< V, B > &max)
Definition: artifact.cpp:32
Definition: item.h:210
int ammo_remaining() const
Quantity of ammunition currently loaded in tool, gun or auxiliary gunmod.
Definition: item.cpp:7399
bool active
Definition: item.h:2237
void put_in(const item &payload)
Puts the given item into this one, no checks are performed.
Definition: item.cpp:998
void set_var(const std::string &name, int value)
Definition: item.cpp:1003
item & ammo_set(const itype_id &ammo, int qty=-1)
Filter setting the ammo for this instance Any existing ammo is removed.
Definition: item.cpp:593
bool goes_bad() const
whether an item is perishable (can rot)
Definition: item.cpp:5523
const mtype * corpse
Definition: item.h:2172
snippet_id snip_id
Definition: item.h:2206
const itype_id & typeId() const
return the unique identifier of the items underlying type
Definition: item.cpp:8374
bool magazine_integral() const
Does item have an integral magazine (as opposed to allowing detachable magazines)
Definition: item.cpp:7677
bool has_flag(const std::string &flag) const
Definition: item.cpp:5328
itype_id ammo_default(bool conversion=true) const
Get default ammo used by item or a null id if item does not have a default ammo type.
Definition: item.cpp:7613
time_point last_rot_check
Time when the rot calculation was last performed.
Definition: item.h:2225
const std::set< ammotype > & ammo_types(bool conversion=true) const
Set of ammo types (ammunition_type) used by item.
Definition: item.cpp:7582
int item_counter
Definition: item.h:2208
cata::value_ptr< relic > relic_data
Definition: item.h:2197
snippet_id random_id_from_category(const std::string &cat) const
Returns the id of a random snippet out of the given category.
const T & obj() const
Returns the actual object this id refers to.
Definition: achievement.cpp:60
const std::string & str() const
Returns the identifier as plain std::string.
Definition: string_id.h:255
static const string_id< mtype > & NULL_ID()
Returns a null id whose string_id<T>::is_null() must always return true.
static const std::string flag_NANOFAB_TEMPLATE("NANOFAB_TEMPLATE")
static const std::string flag_CORPSE("CORPSE")
item item_from(const item_group_id &group_id, const time_point &birthday)
Returns a random item from the item group, handles packaged food by putting it into its container and...
Definition: item_group.cpp:589
std::string snippet_category
Definition: itype.h:875
cata::value_ptr< islot_gun > gun
Definition: itype.h:827
cata::value_ptr< islot_tool > tool
Definition: itype.h:817
int charges_default() const
Definition: itype.cpp:98
cata::value_ptr< relic > relic_data
Definition: itype.h:835
cata::value_ptr< islot_magazine > magazine
Definition: itype.h:829
int countdown_interval
Default countdown interval (if any) for item.
Definition: itype.h:921
snippet_library SNIPPET
string_id< Item_group > item_group_id
Definition: type_id.h:77

References active, ammo_default(), ammo_remaining(), ammo_set(), ammo_types(), bday, charges, itype::charges_default(), corpse, itype::countdown_interval, flag_CORPSE(), flag_NANOFAB_TEMPLATE(), goes_bad(), itype::gun, has_flag(), item(), item_counter, item_group::item_from(), last_rot_check, itype::magazine, magazine_integral(), string_id< mtype >::NULL_ID(), string_id< T >::obj(), put_in(), snippet_library::random_id_from_category(), relic_data, itype::relic_data, rng(), set_flag(), set_var(), snip_id, SNIPPET, itype::snippet_category, string_id< T >::str(), itype::tool, calendar::turn, type, and typeId().

◆ item() [6/11]

item::item ( const itype_id id,
time_point  turn,
default_charges_tag  tag 
)

Definition at line 440 of file item.cpp.

441 : item( & * id, turn, tag ) {}

◆ item() [7/11]

item::item ( const itype type,
time_point  turn,
default_charges_tag   
)

Definition at line 437 of file item.cpp.

438 : item( type, turn, type->charges_default() ) {}

◆ item() [8/11]

item::item ( const itype_id id,
time_point  turn,
solitary_tag  tag 
)

Definition at line 446 of file item.cpp.

447 : item( & * id, turn, tag ) {}

◆ item() [9/11]

item::item ( const itype type,
time_point  turn,
solitary_tag   
)

Definition at line 443 of file item.cpp.

444 : item( type, turn, type->count_by_charges() ? 1 : -1 ) {}
bool count_by_charges() const
Definition: itype.cpp:93

◆ item() [10/11]

item::item ( const recipe rec,
int  qty,
std::list< item items,
std::vector< item_comp selections 
)

For constructing in-progress crafts.

Definition at line 467 of file item.cpp.

468 : item( "craft", calendar::turn, qty )
469{
470 craft_data_ = cata::make_value<craft_data>();
471 craft_data_->making = rec;
472 components = items;
473 craft_data_->comps_used = selections;
474
475 if( is_food() ) {
476 active = true;
478 if( goes_bad() ) {
479 const item *most_rotten = get_most_rotten_component( *this );
480 if( most_rotten ) {
481 set_relative_rot( most_rotten->get_relative_rot() );
482 }
483 }
484 }
485
486 for( item &component : components ) {
487 for( const std::string &f : component.item_tags ) {
488 if( json_flag::get( f ).craft_inherit() ) {
489 set_flag( f );
490 }
491 }
492 for( const std::string &f : component.type->get_flags() ) {
493 if( json_flag::get( f ).craft_inherit() ) {
494 set_flag( f );
495 }
496 }
497 }
498 // this extra section is so that in-progress crafts will correctly display expected flags.
499 for( const std::string &flag : rec->flags_to_delete ) {
500 unset_flag( flag );
501 }
502}
cata::value_ptr< craft_data > craft_data_
Definition: item.h:2194
std::list< item > components
Definition: item.h:2162
bool is_food() const
Definition: item.cpp:6617
item & set_flag(const std::string &flag)
Idempotent filter setting an item specific flag.
Definition: item.cpp:5357
item & unset_flag(const std::string &flag)
Idempotent filter removing an item specific flag.
Definition: item.cpp:5363
void set_relative_rot(double val)
Set current item rot relative to shelf life (no-op if item does not spoil)
Definition: item.cpp:5564
double get_relative_rot() const
Get rot value relative to shelf life (or 0 if item does not spoil)
Definition: item.cpp:5556
static const json_flag & get(const std::string &id)
Fetches flag definition (or null flag if not found)
Definition: flag.cpp:70
std::set< std::string > flags_to_delete
Definition: recipe.h:115
static const item * get_most_rotten_component(const item &craft)
Definition: item.cpp:454
itype_id type
Definition: requirements.h:58
const FlagsSetType & get_flags() const
Definition: itype.cpp:156

References active, bday, components, craft_data_, recipe::flags_to_delete, json_flag::get(), itype::get_flags(), get_most_rotten_component(), get_relative_rot(), goes_bad(), is_food(), last_rot_check, set_flag(), set_relative_rot(), component::type, and unset_flag().

◆ item() [11/11]

template<typename... Args>
item::item ( const std::string &  itype,
Args &&...  args 
)
inline

Definition at line 240 of file item.h.

240 :
241 item( itype_id( itype ), std::forward<Args>( args )... )
242 {}
Definition: itype.h:804

◆ ~item()

item::~item ( )
default

Member Function Documentation

◆ acid_resist()

int item::acid_resist ( bool  to_self = false,
int  base_env_resist = 0 
) const

Resistance against different damage types (damage_type).

Larger values means more resistance are thereby better, but there is no absolute value to compare them to. The values can be interpreted as chance (one_in) of damaging the item when exposed to the type of damage.

Parameters
to_selfIf this is true, it returns item's own resistance, not one it gives to wearer.
base_env_resistWill override the base environmental resistance (to allow hypothetical calculations for gas masks).

Definition at line 6152 of file item.cpp.

6153{
6154 if( to_self ) {
6155 // Currently no items are damaged by acid
6156 return INT_MAX;
6157 }
6158
6159 float resist = 0.0;
6161 if( is_null() ) {
6162 return 0.0;
6163 }
6164
6165 const std::vector<const material_type *> mat_types = made_of_types();
6166 if( !mat_types.empty() ) {
6167 // Not sure why cut and bash get an armor thickness bonus but acid doesn't,
6168 // but such is the way of the code.
6169
6170 for( const material_type *mat : mat_types ) {
6171 resist += mat->acid_resist();
6172 }
6173 // Average based on number of materials.
6174 resist /= mat_types.size();
6175 }
6176
6177 const int env = get_env_resist( base_env_resist );
6178 if( env < 10 ) {
6179 // Low env protection means it doesn't prevent acid seeping in.
6180 resist *= env / 10.0f;
6181 }
6182
6183 return std::lround( resist + mod );
6184}
float get_clothing_mod_val(clothing_mod_type type) const
Definition: item.cpp:10172
bool is_null() const
Definition: item.cpp:735
std::vector< const material_type * > made_of_types() const
Same as made_of(), but returns the material_type directly.
Definition: item.cpp:6451
int get_env_resist(int override_base_resist=0) const
Returns the resistance to environmental effects (islot_armor::env_resist) that this item provides whe...
Definition: item.cpp:5788
@ clothing_mod_type_acid
Definition: clothing_mod.h:17

References clothing_mod_type_acid, get_clothing_mod_val(), get_env_resist(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), and sew_advanced_actor::use().

◆ activate()

item & item::activate ( )

Filter converting instance to active state.

Definition at line 560 of file item.cpp.

561{
562 if( active ) {
563 return *this; // no-op
564 }
565
566 if( type->countdown_interval > 0 ) {
568 }
569
570 active = true;
571
572 return *this;
573}

References active, itype::countdown_interval, item_counter, and type.

Referenced by iuse::cable_attach(), make_gun_projectile(), process(), and process_internal().

◆ actualize_rot()

bool item::actualize_rot ( const tripoint pnt,
temperature_flag  temperature,
const weather_manager weather 
)

Whether the item has to be removed as it has rotten away completely.

May change the item as it calls process_rot()

Parameters
pntThe position of the item on the current map.
temperatureFlag for special locations that affect temperature.
weatherWeather manager to supply temperature.
Returns
true if the item has rotten away and should be removed, false otherwise.

Definition at line 8820 of file item.cpp.

8822{
8823 if( goes_bad() ) {
8824 return process_rot( false, pnt, nullptr, temperature, weather );
8825 } else if( type->container && type->container->preserves ) {
8826 // Containers like tin cans preserves all items inside, they do not rot at all.
8827 return false;
8828 } else if( type->container && type->container->seals ) {
8829 // Items inside rot but do not vanish as the container seals them in.
8830 for( item *c : contents.all_items_top() ) {
8831 if( c->goes_bad() ) {
8832 c->process_rot( true, pnt, nullptr, temperature, weather );
8833 }
8834 }
8835 return false;
8836 } else {
8837 std::vector<item *> removed_items;
8838 // Check and remove rotten contents, but always keep the container.
8839 for( item *it : contents.all_items_top() ) {
8840 if( it->actualize_rot( pnt, temperature, weather ) ) {
8841 removed_items.push_back( it );
8842 }
8843 }
8844 for( item *it : removed_items ) {
8845 remove_item( *it );
8846 }
8847
8848 return false;
8849 }
8850}
std::list< item * > all_items_top()
returns a list of pointers to all top-level items
item_contents contents
Definition: item.h:2161
bool process_rot(const tripoint &pos)
Update temperature for things like food Update rot for things that perish All items that rot also hav...
Definition: item.cpp:8967
item remove_item(item &it)
Removes and returns the item which must be contained by this instance.
Definition: visitable.cpp:564
constexpr double c
Definition: magic.cpp:1032
quantity< int, temperature_in_millidegree_celsius_tag > temperature
cata::value_ptr< islot_container > container
Slots for various item type properties.
Definition: itype.h:816

References item_contents::all_items_top(), c, itype::container, contents, goes_bad(), process_rot(), visitable< item >::remove_item(), and type.

◆ add_technique()

void item::add_technique ( const matec_id tech)

Add the given technique to the item specific techniques.

Note that other items of the same type are not affected by this.

Definition at line 5469 of file item.cpp.

5470{
5471 techniques.insert( tech );
5472}
std::set< matec_id > techniques
Definition: item.h:2174

References techniques.

Referenced by mdeath::jabberwock().

◆ age()

◆ allow_crafting_component()

bool item::allow_crafting_component ( ) const

Permits filthy components, should only be used as a helper in creating filters.

Definition at line 8554 of file item.cpp.

8555{
8556 if( is_toolmod() && is_irremovable() ) {
8557 return false;
8558 }
8559
8560 // vehicle batteries are implemented as magazines of charge
8561 if( is_magazine() && ammo_types().count( ammo_battery ) ) {
8562 return true;
8563 }
8564
8565 // fixes #18886 - turret installation may require items with irremovable mods
8566 if( is_gun() ) {
8567 bool valid = true;
8568 visit_items( [&]( const item * it ) {
8569 if( this == it ) {
8570 return VisitResponse::NEXT;
8571 }
8572 if( !( it->is_magazine() || ( it->is_gunmod() && it->is_irremovable() ) ) ) {
8573 valid = false;
8574 return VisitResponse::ABORT;
8575 }
8576 return VisitResponse::NEXT;
8577 } );
8578 return valid;
8579 }
8580
8581 return contents.empty();
8582}
bool empty() const
int count() const
If count_by_charges(), returns charges, otherwise 1.
Definition: item.cpp:6035
bool is_irremovable() const
Definition: item.cpp:6800
bool is_gun() const
Can this item be used to perform a ranged attack?
Definition: item.cpp:6542
bool is_toolmod() const
Definition: item.cpp:6790
bool is_gunmod() const
Definition: item.cpp:6572
bool is_magazine() const
Definition: item.cpp:6582
VisitResponse visit_items(const std::function< VisitResponse(item *, item *)> &func)
Traverses this object and any child items contained using a visitor pattern.
Definition: visitable.cpp:422
static const ammotype ammo_battery("battery")

References ammo_battery, ammo_types(), contents, count(), item_contents::empty(), is_gun(), is_gunmod(), is_irremovable(), is_magazine(), is_toolmod(), NEXT, and visitable< item >::visit_items().

◆ already_used_by_player()

bool item::already_used_by_player ( const player p) const

Check whether the item has been marked (by calling mark_as_used_by_player) as used by this specific player.

Definition at line 8869 of file item.cpp.

8870{
8871 const auto it = item_vars.find( USED_BY_IDS );
8872 if( it == item_vars.end() ) {
8873 return false;
8874 }
8875 // USED_BY_IDS always starts *and* ends with a ';', the search string
8876 // ';<id>;' matches at most one part of USED_BY_IDS, and only when exactly that
8877 // id has been added.
8878 const std::string needle = string_format( ";%d;", p.getID().get_value() );
8879 return it->second.find( needle ) != std::string::npos;
8880}
character_id getID() const
Definition: character.cpp:492
int get_value() const
Definition: character_id.h:23
std::map< std::string, std::string > item_vars
Definition: item.h:2171
static const std::string USED_BY_IDS("USED_BY_IDS")
std::string string_format(std::string_view format, Args &&...args)
Simple wrapper over string_formatter::parse.

References character_id::get_value(), Character::getID(), item_vars, string_format(), and USED_BY_IDS().

Referenced by tname(), and reveal_map_actor::use().

◆ ammo_capacity() [1/2]

◆ ammo_capacity() [2/2]

int item::ammo_capacity ( bool  potential_capacity) const
Parameters
potential_capacitywhether to try a default magazine if necessary

Definition at line 7431 of file item.cpp.

7432{
7433 int res = 0;
7434
7435 const item *mag = magazine_current();
7436 if( mag ) {
7437 return mag->ammo_capacity();
7438 }
7439
7440 if( is_tool() ) {
7441 res = type->tool->max_charges;
7442 if( res == 0 && magazine_default() && potential_capacity ) {
7443 res = magazine_default()->magazine->capacity;
7444 }
7445 for( const item *e : toolmods() ) {
7446 res *= e->type->mod->capacity_multiplier;
7447 }
7448 }
7449
7450 if( is_gun() ) {
7451 res = type->gun->clip;
7452 for( const item *e : gunmods() ) {
7453 res *= e->type->mod->capacity_multiplier;
7454 }
7455 }
7456
7457 if( is_magazine() ) {
7458 res = type->magazine->capacity;
7459 }
7460
7461 if( is_bandolier() ) {
7462 return dynamic_cast<const bandolier_actor *>
7463 ( type->get_use( "bandolier" )->get_actor_ptr() )->capacity;
7464 }
7465
7466 return res;
7467}
Store ammo and later reload using it.
Definition: iuse_actor.h:884
std::vector< item * > toolmods()
Returns all toolmods currently attached to this item (always empty if item not a tool)
Definition: item.cpp:5474
bool is_tool() const
Definition: item.cpp:6983
itype_id magazine_default(bool conversion=true) const
Get the default magazine type (if any) for the current effective ammo type.
Definition: item.cpp:7692
bool is_bandolier() const
Definition: item.cpp:6597
item * magazine_current()
Currently loaded magazine (if any)
Definition: item.cpp:7739
std::vector< item * > gunmods()
Returns all gunmods currently attached to this item (always empty if item not a gun)
Definition: item.cpp:7752
const use_function * get_use(const std::string &iuse_name) const
Definition: itype.cpp:166
iuse_actor * get_actor_ptr()
Definition: iuse.h:315

References ammo_capacity(), use_function::get_actor_ptr(), itype::get_use(), itype::gun, gunmods(), is_bandolier(), is_gun(), is_magazine(), is_tool(), itype::magazine, magazine_current(), magazine_default(), itype::tool, toolmods(), and type.

◆ ammo_consume()

int item::ammo_consume ( int  qty,
const tripoint pos 
)

Consume ammo (if available) and return the amount of ammo that was consumed.

Parameters
qtymaximum amount of ammo that should be consumed
poscurrent location of item, used for ejecting magazines and similar effects
Returns
amount of ammo consumed which will be between 0 and qty

Definition at line 7497 of file item.cpp.

7498{
7499 if( qty < 0 ) {
7500 debugmsg( "Cannot consume negative quantity of ammo for %s", tname() );
7501 return 0;
7502 }
7503
7504 item *mag = magazine_current();
7505 if( mag ) {
7506 const int res = mag->ammo_consume( qty, pos );
7507 if( res && ammo_remaining() == 0 ) {
7508 if( mag->has_flag( flag_MAG_DESTROY ) ) {
7509 remove_item( *mag );
7510 } else if( mag->has_flag( flag_MAG_EJECT ) ) {
7511 get_map().add_item( pos, *mag );
7512 remove_item( *mag );
7513 }
7514 }
7515 return res;
7516 }
7517
7518 if( is_magazine() ) {
7519 int need = qty;
7520 while( !contents.empty() ) {
7521 item &e = contents.front();
7522 if( need >= e.charges ) {
7523 need -= e.charges;
7525 } else {
7526 e.charges -= need;
7527 need = 0;
7528 break;
7529 }
7530 }
7531 return qty - need;
7532
7533 } else if( is_tool() || is_gun() ) {
7534 qty = std::min( qty, charges );
7536 avatar &you = get_avatar();
7539 }
7540 charges -= qty;
7541 if( charges == 0 ) {
7542 curammo = nullptr;
7543 }
7544 return qty;
7545 }
7546
7547 return 0;
7548}
avatar & get_avatar()
Definition: avatar.cpp:104
void mod_power_level(const units::energy &npower)
Definition: character.cpp:1922
units::energy get_power_level() const
Definition: character.cpp:1902
Definition: avatar.h:55
item & front()
this is an artifact of the previous code using front() everywhere for contents.
std::string tname(unsigned int quantity=1, bool with_prefix=true, unsigned int truncate=0) const
Return the (translated) item name.
Definition: item.cpp:4574
int ammo_consume(int qty, const tripoint &pos)
Consume ammo (if available) and return the amount of ammo that was consumed.
Definition: item.cpp:7497
const itype * curammo
Definition: item.h:2170
item & add_item(const tripoint &p, item new_item)
Place an item on the map, despite the parameter name, this is not necessarily a new item.
Definition: map.cpp:4454
#define debugmsg(...)
Debug message of level DL::Error and class DC::DebugMsg, also includes the source file name and line,...
Definition: debug.h:74
static const std::string flag_USES_BIONIC_POWER("USES_BIONIC_POWER")
static const std::string flag_MAG_DESTROY("MAG_DESTROY")
static const std::string flag_MAG_EJECT("MAG_EJECT")
map & get_map()
Definition: map.cpp:147
constexpr value_type to_kilojoule(const quantity< value_type, energy_in_joule_tag > &v)
Definition: units_energy.h:46
constexpr quantity< value_type, energy_in_joule_tag > from_kilojoule(const value_type v)
Definition: units_energy.h:32

References map::add_item(), ammo_consume(), ammo_remaining(), charges, contents, curammo, debugmsg, item_contents::empty(), flag_MAG_DESTROY(), flag_MAG_EJECT(), flag_USES_BIONIC_POWER(), units::from_kilojoule(), item_contents::front(), get_avatar(), get_map(), Character::get_power_level(), has_flag(), is_gun(), is_magazine(), is_tool(), magazine_current(), Character::mod_power_level(), visitable< item >::remove_item(), tname(), and units::to_kilojoule().

Referenced by ammo_consume(), vehicle_part::ammo_consume(), Character::consume_charges(), iuse::einktabletpc(), ranged::fire_gun(), activity_handlers::game_do_turn(), iuse::gasmask(), iuse::multicooker(), iuse::note_bionics(), activity_handlers::oxytorch_do_turn(), npc::pretend_fire(), process_tool(), reload(), activity_handlers::repair_item_finish(), toolweapon_on(), and activity_handlers::vibe_do_turn().

◆ ammo_current()

itype_id item::ammo_current ( ) const

Specific ammo type, returns "null" if item is neither ammo nor loaded with any.

Definition at line 7576 of file item.cpp.

7577{
7578 const itype *ammo = ammo_data();
7579 return ammo ? ammo->get_id() : itype_id::NULL_ID();
7580}
const itype * ammo_data() const
Specific ammo data, returns nullptr if item is neither ammo nor loaded with any.
Definition: item.cpp:7550
const itype_id & get_id() const
Definition: itype.cpp:88

References ammo_data(), itype::get_id(), and string_id< itype >::NULL_ID().

Referenced by vehicle_part::ammo_current(), turret_data::ammo_options(), npc::confident_gun_mode_range(), display_name(), aim_activity_actor::do_turn(), ranged::fire_gun(), avatar_action::fire_wielded_weapon(), get_remaining_capacity_for_liquid(), gun_noise(), npc_ai::gun_value(), ideal_ranged_dps(), is_reloadable_helper(), make_gun_projectile(), parse_tags(), remove_ammo(), activity_handlers::repair_item_finish(), stacks_with(), avatar_funcs::unload_item(), iuse_transform::use(), and weight().

◆ ammo_data()

const itype * item::ammo_data ( ) const

Specific ammo data, returns nullptr if item is neither ammo nor loaded with any.

Definition at line 7550 of file item.cpp.

7551{
7552 const item *mag = magazine_current();
7553 if( mag ) {
7554 return mag->ammo_data();
7555 }
7556
7557 if( is_ammo() ) {
7558 return type;
7559 }
7560
7561 if( is_magazine() ) {
7562 return !contents.empty() ? contents.front().ammo_data() : nullptr;
7563 }
7564
7565 auto mods = is_gun() ? gunmods() : toolmods();
7566 for( const item *e : mods ) {
7567 if( !e->type->mod->ammo_modifier.empty() && e->ammo_current() &&
7568 e->ammo_current().is_valid() ) {
7569 return &*e->ammo_current();
7570 }
7571 }
7572
7573 return curammo;
7574}
bool is_ammo() const
Definition: item.cpp:6607

References ammo_data(), contents, curammo, item_contents::empty(), item_contents::front(), gunmods(), is_ammo(), is_gun(), is_magazine(), magazine_current(), toolmods(), and type.

Referenced by ammo_current(), ammo_data(), turret_data::ammo_data(), ammo_effects(), ammo_info(), cycle_action(), Character::deactivate_bionic(), avatar_action::fire_wielded_weapon(), gun_damage(), gun_dispersion(), gun_info(), gun_noise(), gun_range(), gun_recoil(), ranged::handle_gun_damage(), is_reloadable_helper(), make_gun_projectile(), Item_modifier::modify(), price(), character_funcs::select_ammo(), target_ui::update_ammo_range_from_gun_mode(), weapon_inventory_preset::weapon_inventory_preset(), and weight().

◆ ammo_default()

itype_id item::ammo_default ( bool  conversion = true) const

Get default ammo used by item or a null id if item does not have a default ammo type.

Parameters
conversionwhether to include the effect of any flags or mods which convert the type
Returns
itype_id::NULL_ID() if item does not use a specific ammo type (and is consequently not reloadable)

Definition at line 7613 of file item.cpp.

7614{
7615 if( is_magazine() ) {
7616 return type->magazine->default_ammo;
7617 }
7618
7619 const std::set<ammotype> &atypes = ammo_types( conversion );
7620 if( !atypes.empty() ) {
7621 itype_id res = ammotype( *atypes.begin() )->default_ammotype();
7622 if( !res.is_empty() ) {
7623 return res;
7624 }
7625 }
7626 return itype_id::NULL_ID();
7627}
const itype_id & default_ammotype() const
Definition: ammo.h:21
bool is_empty() const
Returns whether this id is empty.
Definition: string_id.h:298
string_id< ammunition_type > ammotype
Definition: type_id.h:12

References ammo_types(), ammunition_type::default_ammotype(), string_id< T >::is_empty(), is_magazine(), itype::magazine, string_id< itype >::NULL_ID(), and type.

Referenced by basecamp::add_resource(), turret_data::ammo_current(), crafting::complete_disassemble(), game::dump_stats(), npc::enough_time_to_reload(), inventory::form_from_map(), gun_info(), npc_ai::gun_value(), ideal_ranged_dps(), item(), Item_modifier::modify(), relic_funcs::process_recharge_entry(), gun_actor::shoot(), starting_inv(), iexamine::use_furn_fake_item(), npc_ai::wielded_value(), and debug_menu::wishitem().

◆ ammo_effects()

std::set< ammo_effect_str_id > item::ammo_effects ( bool  with_ammo = true) const

Get ammo effects for item optionally inclusive of any resulting from the loaded ammo.

Definition at line 7645 of file item.cpp.

7646{
7647 if( !is_gun() ) {
7648 return std::set<ammo_effect_str_id>();
7649 }
7650
7651 std::set<ammo_effect_str_id> res = type->gun->ammo_effects;
7652 if( with_ammo && ammo_data() ) {
7653 res.insert( ammo_data()->ammo->ammo_effects.begin(), ammo_data()->ammo->ammo_effects.end() );
7654 }
7655
7656 for( const item *mod : gunmods() ) {
7657 res.insert( mod->type->gunmod->ammo_effects.begin(), mod->type->gunmod->ammo_effects.end() );
7658 }
7659
7660 return res;
7661}

References ammo_data(), itype::gun, gunmods(), is_gun(), and type.

Referenced by turret_data::ammo_effects(), gun_noise(), ranged::handle_gun_damage(), and make_gun_projectile().

◆ ammo_info()

void item::ammo_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 1907 of file item.cpp.

1909{
1910 if( is_gun() || !ammo_data() || !parts->test( iteminfo_parts::AMMO_REMAINING_OR_TYPES ) ) {
1911 return;
1912 }
1913
1914 const std::string space = " ";
1915 if( ammo_remaining() > 0 ) {
1916 info.emplace_back( "AMMO", _( "<bold>Ammunition</bold>: " ),
1917 ammo_data()->nname( ammo_remaining() ) );
1918 } else if( is_ammo() ) {
1919 info.emplace_back( "AMMO", _( "<bold>Ammunition type</bold>: " ), ammo_type()->name() );
1920 }
1921
1922 const islot_ammo &ammo = *ammo_data()->ammo;
1923 if( !ammo.damage.empty() || ammo.force_stat_display ) {
1924 bool has_flat_dmg = !ammo.damage.empty() && ammo.damage.damage_units.front().amount > 0;
1925 bool display_flat_dmg = parts->test( iteminfo_parts::AMMO_DAMAGE_VALUE );
1926 // TODO: Multiple units
1927 bool has_dmg_multiplier = ammo.damage.damage_units.front().damage_multiplier != 1.0;
1928 bool display_dmg_multiplier = parts->test( iteminfo_parts::AMMO_DAMAGE_PROPORTIONAL );
1929 bool didnt_print_dmg = false;
1930 if( has_flat_dmg && has_dmg_multiplier
1931 && has_dmg_multiplier && display_dmg_multiplier ) {
1932 info.emplace_back( "AMMO", _( "Damage: " ), "",
1934 info.emplace_back( "AMMO", "/", "",
1936 ammo.damage.damage_units.front().damage_multiplier );
1937 // Messy ifs...
1938 } else if( display_dmg_multiplier && ( has_dmg_multiplier || !has_flat_dmg ) ) {
1939 info.emplace_back( "AMMO", _( "Damage multiplier: " ), "",
1941 ammo.damage.damage_units.front().damage_multiplier );
1942 } else if( display_flat_dmg ) {
1943 info.emplace_back( "AMMO", _( "Damage: " ), "",
1945 } else {
1946 didnt_print_dmg = true;
1947 }
1948
1949 // Ugly, but handles edge cases better than mandatory space
1950 static const std::string no_space;
1951 const std::string &maybe_space = didnt_print_dmg ? no_space : space;
1952
1953 // TODO: Deduplicate with damage display
1954 bool has_flat_arpen = get_ranged_pierce( ammo ) != 0;
1955 bool display_flat_arpen = parts->test( iteminfo_parts::AMMO_DAMAGE_AP );
1956 bool has_armor_mult = get_ranged_armor_mult( ammo ) != 1.0;
1957 bool display_armor_mult = parts->test( iteminfo_parts::AMMO_DAMAGE_AP_PROPORTIONAL );
1958 if( has_flat_arpen && display_flat_arpen
1959 && has_armor_mult && display_armor_mult ) {
1960 info.emplace_back( "AMMO", maybe_space + _( "Armor-pierce: " ), "",
1962 info.emplace_back( "AMMO", "/", "",
1964 get_ranged_armor_mult( ammo ) );
1965 } else if( has_armor_mult && display_armor_mult ) {
1966 info.emplace_back( "AMMO", maybe_space + _( "Armor multiplier: " ), "",
1968 } else if( display_flat_arpen ) {
1969 info.emplace_back( "AMMO", maybe_space + _( "Armor-pierce: " ), get_ranged_pierce( ammo ) );
1970 }
1971 if( parts->test( iteminfo_parts::AMMO_DAMAGE_RANGE ) ) {
1972 info.emplace_back( "AMMO", _( "Range: " ), "", iteminfo::no_newline, ammo.shape
1973 ? static_cast<int>( ammo.shape->get_range() )
1974 : ammo.range );
1975 }
1977 info.emplace_back( "AMMO", space + _( "Dispersion: " ), "",
1979 }
1981 info.emplace_back( "AMMO", _( "Recoil: " ), "",
1983 }
1984 }
1985
1986 // TODO: De-hardcode. Have it imply a flag? Just include description_on_item in ammo_effect struct?
1987 std::vector<std::string> fx;
1988 if( ammo.shape &&
1989 parts->test( iteminfo_parts::AMMO_SHAPE ) ) {
1990 fx.emplace_back( string_format(
1991 _( "This ammo will produce effects with the following shape:\n<bold>%s</bold>" ),
1992 ammo.shape->get_description() ) );
1993 }
1994 if( ammo.ammo_effects.count( ammo_effect_RECYCLED ) &&
1996 fx.emplace_back( _( "This ammo has been <bad>hand-loaded</bad>." ) );
1997 }
1998 if( ammo.ammo_effects.count( ammo_effect_BLACKPOWDER ) &&
2000 fx.emplace_back(
2001 _( "This ammo has been loaded with <bad>blackpowder</bad>, and will quickly "
2002 "clog up most guns, and cause rust if the gun is not cleaned." ) );
2003 }
2004 if( ammo.ammo_effects.count( ammo_effect_NEVER_MISFIRES ) &&
2006 fx.emplace_back( _( "This ammo <good>never misfires</good>." ) );
2007 }
2008 if( ammo.ammo_effects.count( ammo_effect_INCENDIARY ) &&
2010 fx.emplace_back( _( "This ammo <neutral>starts fires</neutral>." ) );
2011 }
2012 if( !fx.empty() ) {
2014 for( const std::string &e : fx ) {
2015 info.emplace_back( "AMMO", e );
2016 }
2017 }
2018}
static std::string nname(const itype_id &id, unsigned int quantity=1)
Returns the translated item name for the item with given id.
Definition: item.cpp:9951
std::vector< iteminfo > info() const
Return all the information about the item and its type as a vector.
Definition: item.cpp:3991
ammotype ammo_type() const
Ammo type of an ammo item.
Definition: item.cpp:7605
bool test(const iteminfo_parts &value) const
static const ammo_effect_str_id ammo_effect_NEVER_MISFIRES("NEVER_MISFIRES")
static float get_ranged_armor_mult(const common_ranged_data &ranged)
Definition: item.cpp:1103
static const ammo_effect_str_id ammo_effect_INCENDIARY("INCENDIARY")
static const ammo_effect_str_id ammo_effect_BLACKPOWDER("BLACKPOWDER")
static void insert_separation_line(std::vector< iteminfo > &info)
Definition: item.cpp:1304
static int get_ranged_pierce(const common_ranged_data &ranged)
Definition: item.cpp:1094
static const ammo_effect_str_id ammo_effect_RECYCLED("RECYCLED")
@ AMMO_DAMAGE_AP_PROPORTIONAL
std::string name(type dir)
Get Human readable name of a direction.
Definition: overmap.cpp:4129
int dispersion
Dispersion "bonus" from gun.
Definition: itype.h:420
damage_instance damage
Damage, armor piercing and multipliers for each.
Definition: itype.h:412
int range
Range bonus from gun.
Definition: itype.h:416
std::vector< damage_unit > damage_units
Definition: damage.h:52
float total_damage() const
Definition: damage.cpp:75
bool empty() const
Definition: damage.cpp:88
std::optional< bool > force_stat_display
Some combat ammo might not have a damage value Set this to make it show as combat ammo anyway.
Definition: itype.h:701
std::optional< shape_factory > shape
AoE shape or null if it's a projectile.
Definition: itype.h:706
int recoil
Recoil (per shot), roughly equivalent to kinetic energy (in Joules)
Definition: itype.h:681
std::set< ammo_effect_str_id > ammo_effects
See ammo_effect struct.
Definition: itype.h:673
@ no_newline
Do not follow with a newline.
Definition: item.h:146
@ is_decimal
Print as decimal rather than integer.
Definition: item.h:144
@ lower_is_better
Lower values are better for this stat.
Definition: item.h:147
cata::value_ptr< islot_ammo > ammo
Definition: itype.h:832
#define _(msg)
Definition: translations.h:116

References _, itype::ammo, AMMO_DAMAGE_AP, AMMO_DAMAGE_AP_PROPORTIONAL, AMMO_DAMAGE_DISPERSION, AMMO_DAMAGE_PROPORTIONAL, AMMO_DAMAGE_RANGE, AMMO_DAMAGE_RECOIL, AMMO_DAMAGE_VALUE, ammo_data(), ammo_effect_BLACKPOWDER, ammo_effect_INCENDIARY, ammo_effect_NEVER_MISFIRES, ammo_effect_RECYCLED, islot_ammo::ammo_effects, AMMO_FX_BLACKPOWDER, AMMO_FX_CANTMISSFIRE, AMMO_FX_INCENDIARY, AMMO_FX_RECYCLED, ammo_remaining(), AMMO_REMAINING_OR_TYPES, AMMO_SHAPE, ammo_type(), common_ranged_data::damage, damage_instance::damage_units, common_ranged_data::dispersion, damage_instance::empty(), islot_ammo::force_stat_display, get_ranged_armor_mult(), get_ranged_pierce(), info(), insert_separation_line(), is_ammo(), iteminfo::is_decimal, is_gun(), iteminfo::lower_is_better, om_direction::name(), nname(), iteminfo::no_newline, common_ranged_data::range, islot_ammo::recoil, islot_ammo::shape, sign::space, string_format(), iteminfo_query::test(), and damage_instance::total_damage().

Referenced by info().

◆ ammo_remaining()

int item::ammo_remaining ( ) const

Quantity of ammunition currently loaded in tool, gun or auxiliary gunmod.

Definition at line 7399 of file item.cpp.

7400{
7401 const item *mag = magazine_current();
7402 if( mag ) {
7403 return mag->ammo_remaining();
7404 }
7405
7406 if( is_tool() || is_gun() ) {
7407 // includes auxiliary gunmods
7409 int power = units::to_kilojoule( get_avatar().get_power_level() );
7410 return power;
7411 }
7412 return charges;
7413 }
7414
7415 if( is_magazine() || is_bandolier() ) {
7416 int res = 0;
7417 for( const item *e : contents.all_items_top() ) {
7418 res += e->charges;
7419 }
7420 return res;
7421 }
7422
7423 return 0;
7424}

References item_contents::all_items_top(), ammo_remaining(), charges, contents, flag_USES_BIONIC_POWER(), get_avatar(), has_flag(), is_bandolier(), is_gun(), is_magazine(), is_tool(), magazine_current(), and units::to_kilojoule().

Referenced by game::add_artifact_dreams(), ammo_consume(), character_funcs::ammo_count_for(), ammo_info(), ammo_remaining(), vehicle_part::ammo_remaining(), turret_data::ammo_remaining(), vehicle_part::ammo_set(), ammo_sufficient(), item_funcs::can_be_unloaded(), turret_data::can_reload(), turret_data::can_unload(), firestarter_actor::can_use(), Character::consume_charges(), iuse::cs_lajatang_off(), Character::deactivate_bionic(), display_name(), npc::do_reload(), aim_activity_actor::do_turn(), iuse::ehandcuffs(), iuse::einktabletpc(), fill_with(), ranged::fire_gun(), character_funcs::fmt_wielded_weapon(), iuse::foodperson(), get_remaining_capacity_for_liquid(), getlight_emit(), gun_recoil(), ranged::gunmode_checks_weapon(), iuse::hand_crank(), activity_handlers::hand_crank_do_turn(), Character::has_enough_charges(), ideal_ranged_dps(), vehicle::interact_with(), is_gunmod_compatible(), is_reloadable_helper(), item(), item_action_generator::map_actions_to_items(), Item_modifier::modify(), iuse::multicooker(), iuse::oxytorch(), target_ui::panel_gun_info(), price(), game::process_artifact(), Character::process_items(), relic_funcs::process_recharge(), process_vehicle_items(), item_reload_option::qty(), iuse::radio_on(), avatar_action::reload(), reload(), activity_handlers::repair_item_finish(), item_funcs::shots_remaining(), iuse::tazer2(), tool_info(), units_remaining(), avatar_funcs::unload_item(), charger_tile::update_internal(), iuse::vibe(), activity_handlers::vibe_do_turn(), wants_to_reload(), wants_to_reload_with(), weapon_inventory_preset::weapon_inventory_preset(), and weight().

◆ ammo_required()

int item::ammo_required ( ) const

Quantity of ammunition consumed per usage of tool or with each shot of gun.

Definition at line 7469 of file item.cpp.

7470{
7471 if( is_tool() ) {
7472 return std::max( type->charges_to_use(), 0 );
7473 }
7474
7475 if( is_gun() ) {
7476 if( ammo_types().empty() ) {
7477 return 0;
7478 } else if( has_flag( flag_FIRE_100 ) ) {
7479 return 100;
7480 } else if( has_flag( flag_FIRE_50 ) ) {
7481 return 50;
7482 } else if( has_flag( flag_FIRE_20 ) ) {
7483 return 20;
7484 } else {
7485 return 1;
7486 }
7487 }
7488
7489 return 0;
7490}
static const std::string flag_FIRE_100("FIRE_100")
static const std::string flag_FIRE_50("FIRE_50")
static const std::string flag_FIRE_20("FIRE_20")
int charges_to_use() const
Definition: itype.cpp:110

References ammo_types(), itype::charges_to_use(), flag_FIRE_100(), flag_FIRE_20(), flag_FIRE_50(), has_flag(), is_gun(), is_tool(), and type.

Referenced by character_funcs::ammo_count_for(), turret_data::ammo_options(), ammo_sufficient(), firestarter_actor::can_use(), cauterize_actor::can_use(), Character::consume_charges(), salvage_actor::cut_up(), display_name(), npc::do_reload(), ranged::fire_gun(), mattack::frag(), activity_handlers::game_do_turn(), activatable_inventory_preset::get_denial(), gun_recoil(), ranged::gunmode_checks_weapon(), Character::has_enough_charges(), vehicle::interact_with(), activity_handlers::jackhammer_finish(), item_action_generator::map_actions_to_items(), iuse::oxytorch(), activity_handlers::oxytorch_do_turn(), activity_handlers::pickaxe_finish(), iuse::portable_game(), turret_data::prepare_fire(), npc::pretend_fire(), process_tool(), turret_data::query(), activity_handlers::repair_item_finish(), mattack::rifle(), item_funcs::shots_remaining(), mattack::tankgun(), units_sufficient(), inscribe_actor::use(), cauterize_actor::use(), enzlave_actor::use(), wants_to_reload(), and wants_to_reload_with().

◆ ammo_set()

item & item::ammo_set ( const itype_id ammo,
int  qty = -1 
)

Filter setting the ammo for this instance Any existing ammo is removed.

If necessary a magazine is also added.

Parameters
ammospecific type of ammo (must be compatible with item ammo type)
qtymaximum ammo (capped by item capacity) or negative to fill to capacity
Returns
same instance to allow method chaining

Definition at line 593 of file item.cpp.

594{
595 if( qty < 0 ) {
596 // completely fill an integral or existing magazine
598 qty = ammo_capacity();
599
600 // else try to add a magazine using default ammo count property if set
601 } else if( !magazine_default().is_null() ) {
602 item mag( magazine_default() );
603 if( mag.type->magazine->count > 0 ) {
604 qty = mag.type->magazine->count;
605 } else {
606 qty = item( magazine_default() ).ammo_capacity();
607 }
608 }
609 }
610
611 if( qty <= 0 ) {
612 ammo_unset();
613 return *this;
614 }
615
616 // handle reloadable tools and guns with no specific ammo type as special case
617 if( ( ammo.is_null() && ammo_types().empty() ) || is_money() ) {
618 if( ( is_tool() || is_gun() ) && magazine_integral() ) {
619 curammo = nullptr;
620 charges = std::min( qty, ammo_capacity() );
621 }
622 return *this;
623 }
624
625 // check ammo is valid for the item
626 const itype *atype = &*ammo;
627 if( !atype->ammo || !ammo_types().count( atype->ammo->type ) ) {
628 debugmsg( "Tried to set invalid ammo %s[%d] for %s", atype->get_id(), qty, typeId() );
629 return *this;
630 }
631
632 if( is_magazine() ) {
633 ammo_unset();
634 item set_ammo( ammo, calendar::turn, std::min( qty, ammo_capacity() ) );
635 if( has_flag( flag_NO_UNLOAD ) ) {
636 set_ammo.set_flag( "NO_DROP" );
637 set_ammo.set_flag( "IRREMOVABLE" );
638 }
639 put_in( set_ammo );
640
641 } else if( magazine_integral() ) {
642 curammo = atype;
643 charges = std::min( qty, ammo_capacity() );
644
645 } else {
646 if( !magazine_current() ) {
648 if( !mag->magazine ) {
649 debugmsg( "Tried to set ammo %s[%d] without suitable magazine for %s",
650 atype->get_id(), qty, typeId() );
651 return *this;
652 }
653
654 // if default magazine too small fetch instead closest available match
655 if( mag->magazine->capacity < qty ) {
656 // as above call to magazine_default successful can infer minimum one option exists
657 auto iter = type->magazines.find( atype->ammo->type );
658 if( iter == type->magazines.end() ) {
659 debugmsg( "%s doesn't have a magazine for %s",
660 typeId(), ammo );
661 return *this;
662 }
663 std::vector<itype_id> opts( iter->second.begin(), iter->second.end() );
664 std::sort( opts.begin(), opts.end(), []( const itype_id & lhs, const itype_id & rhs ) {
665 return lhs->magazine->capacity < rhs->magazine->capacity;
666 } );
667 mag = opts.back();
668 for( const itype_id &e : opts ) {
669 if( e->magazine->capacity >= qty ) {
670 mag = e;
671 break;
672 }
673 }
674 }
675 put_in( item( mag ) );
676 }
677 magazine_current()->ammo_set( ammo, qty );
678 }
679
680 return *this;
681}
bool is_money() const
Definition: item.cpp:6025
item & ammo_unset()
Filter removing all ammo from this instance If the item is neither a tool, gun nor magazine is a no-o...
Definition: item.cpp:683
bool is_null() const
Returns whether this represents the id of the null-object (in which case it's the null-id).
Definition: string_id.h:317
static const std::string flag_NO_UNLOAD("NO_UNLOAD")
std::map< ammotype, std::set< itype_id > > magazines
Magazine types (if any) for each ammo type that can be used to reload this item.
Definition: itype.h:988

References itype::ammo, ammo_capacity(), ammo_set(), ammo_types(), ammo_unset(), charges, count(), curammo, debugmsg, flag_NO_UNLOAD(), itype::get_id(), has_flag(), is_gun(), is_magazine(), is_money(), is_null(), string_id< T >::is_null(), is_tool(), item(), itype::magazine, magazine_current(), magazine_default(), magazine_integral(), itype::magazines, put_in(), set_flag(), calendar::turn, type, and typeId().

Referenced by Character::activate_bionic(), ammo_set(), vehicle_part::ammo_set(), mdeath::broken(), npc::check_toggle_cbm(), crafting::complete_disassemble(), vehicle_part::deserialize(), game::dump_stats(), fill_with(), find_reloadable_cbms(), basecamp::form_crafting_inventory(), gun_info(), npc_ai::gun_value(), activity_handlers::hand_crank_do_turn(), vehicle::interact_with(), item(), Item_modifier::modify(), relic_funcs::process_recharge_entry(), gun_actor::shoot(), npc::starting_weapon(), avatar_funcs::unload_item(), target_ui::update_ammo_range_from_gun_mode(), iuse_transform::use(), npc_ai::wielded_value(), and debug_menu::wishitem().

◆ ammo_sort_name()

std::string item::ammo_sort_name ( ) const

Definition at line 7663 of file item.cpp.

7664{
7665 if( is_magazine() || is_gun() || is_tool() ) {
7666 const std::set<ammotype> &types = ammo_types();
7667 if( !types.empty() ) {
7668 return ammotype( *types.begin() )->name();
7669 }
7670 }
7671 if( is_ammo() ) {
7672 return ammo_type()->name();
7673 }
7674 return "";
7675}
std::string name() const
Definition: ammo.cpp:79

References ammo_type(), ammo_types(), is_ammo(), is_gun(), is_magazine(), is_tool(), and ammunition_type::name().

◆ ammo_sufficient()

bool item::ammo_sufficient ( int  qty = 1) const

Check if sufficient ammo is loaded for given number of uses.

Check if there is enough ammo loaded in a tool for the given number of uses or given number of gun shots. Using this function for this check is preferred because we expect to add support for items consuming multiple ammo types in the future. Users of this function will not need to be refactored when this happens.

Parameters
[in]qtyNumber of uses
Returns
true if ammo sufficient for number of uses is loaded, false otherwise

Definition at line 7492 of file item.cpp.

7493{
7494 return ammo_remaining() >= ammo_required() * qty;
7495}
int ammo_required() const
Quantity of ammunition consumed per usage of tool or with each shot of gun.
Definition: item.cpp:7469

References ammo_remaining(), and ammo_required().

Referenced by can_do_activity_there(), iuse::extinguisher(), ranged::gunmode_checks_weapon(), Character::has_enough_charges(), iuse::jet_injector(), item_action_generator::map_actions_to_items(), mine_activity(), avatar_action::move(), iuse::pheromone(), iuse::portal(), turret_data::query(), iuse::radiocar(), iuse::radiocaron(), examine_item_menu::rate_action_use(), iuse::rm13armor_off(), iuse::shavekit(), gun_actor::shoot(), iuse::stimpack(), and iuse::teleport().

◆ ammo_type()

ammotype item::ammo_type ( ) const

Ammo type of an ammo item.

Returns
ammotype of ammo item or a null id if the item is not ammo

Definition at line 7605 of file item.cpp.

7606{
7607 if( is_ammo() ) {
7608 return type->ammo->type;
7609 }
7610 return ammotype::NULL_ID();
7611}

References itype::ammo, is_ammo(), string_id< ammunition_type >::NULL_ID(), and type.

Referenced by vehicle::add_item(), ammo_info(), ammo_sort_name(), mdeath::broken(), color_in_inventory(), detonate(), character_funcs::find_ammo_helper(), character_funcs::get_ammo_items(), item_reload_option::qty(), reload(), and npc::value().

◆ ammo_types()

const std::set< ammotype > & item::ammo_types ( bool  conversion = true) const

Set of ammo types (ammunition_type) used by item.

Parameters
conversionwhether to include the effect of any flags or mods which convert the type
Returns
empty set if item does not use a specific ammo type (and is consequently not reloadable)

Definition at line 7582 of file item.cpp.

7583{
7584 if( conversion ) {
7585 const std::vector<const item *> &mods = is_gun() ? gunmods() : toolmods();
7586 for( const item *e : mods ) {
7587 if( !e->type->mod->ammo_modifier.empty() ) {
7588 return e->type->mod->ammo_modifier;
7589 }
7590 }
7591 }
7592
7593 if( is_gun() ) {
7594 return type->gun->ammo;
7595 } else if( is_tool() ) {
7596 return type->tool->ammo_id;
7597 } else if( is_magazine() ) {
7598 return type->magazine->type;
7599 }
7600
7601 static std::set<ammotype> atypes = {};
7602 return atypes;
7603}

References itype::gun, gunmods(), is_gun(), is_magazine(), is_tool(), itype::magazine, itype::tool, toolmods(), and type.

Referenced by vehicle::add_item(), allow_crafting_component(), ammo_default(), turret_data::ammo_options(), ammo_required(), ammo_set(), ammo_sort_name(), mdeath::broken(), item_funcs::can_be_unloaded(), color_in_inventory(), common_ammo_default(), craft_has_charges(), display_name(), avatar_action::fire_wielded_weapon(), get_quality(), avatar_funcs::gunmod_add(), vehicle_part::is_battery(), is_gunmod_compatible(), is_money(), is_reloadable(), is_reloadable_helper(), item(), magazine_compatible(), magazine_default(), magazine_info(), Item_modifier::modify(), price(), relic_funcs::process_recharge_entry(), character_funcs::select_ammo(), set_countdown(), tool_info(), avatar_funcs::unload_item(), npc::value(), and weight().

◆ ammo_unset()

item & item::ammo_unset ( )

Filter removing all ammo from this instance If the item is neither a tool, gun nor magazine is a no-op For items reloading using magazines any empty magazine remains present.

Definition at line 683 of file item.cpp.

684{
685 if( !is_tool() && !is_gun() && !is_magazine() ) {
686 // do nothing
687 } else if( is_magazine() ) {
689 } else if( magazine_integral() ) {
690 curammo = nullptr;
691 charges = 0;
692 } else if( magazine_current() ) {
694 }
695
696 return *this;
697}

References ammo_unset(), charges, item_contents::clear_items(), contents, curammo, is_gun(), is_magazine(), is_tool(), magazine_current(), and magazine_integral().

Referenced by ammo_set(), ammo_unset(), vehicle_part::ammo_unset(), iuse::ehandcuffs(), emit_radio_signal(), npc_ai::gun_value(), and ammobelt_actor::use().

◆ animal_armor_info()

void item::animal_armor_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2735 of file item.cpp.

2737{
2738 if( !is_pet_armor() ) {
2739 return;
2740 }
2741
2742 const std::string space = " ";
2743
2744 int converted_storage_scale = 0;
2745 const double converted_storage = round_up( convert_volume( get_storage().value(),
2746 &converted_storage_scale ), 2 );
2747 if( parts->test( iteminfo_parts::ARMOR_STORAGE ) && converted_storage > 0 ) {
2748 const iteminfo::flags f = converted_storage_scale == 0 ? iteminfo::no_flags : iteminfo::is_decimal;
2749 info.push_back( iteminfo( "ARMOR", space + _( "Storage: " ),
2750 string_format( "<num> %s", volume_units_abbr() ),
2751 f, converted_storage ) );
2752 }
2753
2754 // Whatever the last entry was, we want a newline at this point
2755 info.back().bNewLine = true;
2756
2757 armor_protection_info( info, parts, batch, debug );
2758}
double round_up(double val, unsigned int dp)
Round a value up at a given decimal place.
units::volume get_storage() const
Returns the storage amount (islot_armor::storage) that this item provides when worn.
Definition: item.cpp:5757
void armor_protection_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2509
bool is_pet_armor(bool on_pet=false) const
Definition: item.cpp:6723
constexpr auto debug
Definition: options.cpp:151
Value and metadata for one property of an item.
Definition: item.h:107
flags
Definition: item.h:142
@ no_flags
Definition: item.h:143
const char * volume_units_abbr()
Create an abbreviated units label for a volume value.
double convert_volume(int volume)
Convert volume from ml to units defined by user.

References _, armor_protection_info(), ARMOR_STORAGE, convert_volume(), debug, get_storage(), info(), iteminfo::is_decimal, is_pet_armor(), iteminfo::no_flags, round_up(), sign::space, string_format(), iteminfo_query::test(), and volume_units_abbr().

Referenced by info().

◆ armor_fit_info()

void item::armor_fit_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2760 of file item.cpp.

2762{
2763 if( !is_armor() ) {
2764 return;
2765 }
2766
2767 avatar &you = get_avatar();
2768 int encumbrance = get_encumber( you );
2769 const sizing sizing_level = get_sizing( you, encumbrance != 0 );
2770
2773 info.push_back( iteminfo( "DESCRIPTION",
2774 _( "* This item can be <info>worn with a "
2775 "helmet</info>." ) ) );
2776 }
2777
2779 switch( sizing_level ) {
2781 if( has_flag( flag_FIT ) ) {
2782 info.emplace_back( "DESCRIPTION",
2783 _( "* This clothing <info>fits</info> you perfectly." ) );
2784 }
2785 break;
2787 if( has_flag( flag_FIT ) ) {
2788 info.emplace_back( "DESCRIPTION", _( "* This clothing <info>fits</info> "
2789 "your large frame perfectly." ) );
2790 }
2791 break;
2793 if( has_flag( flag_FIT ) ) {
2794 info.emplace_back( "DESCRIPTION", _( "* This clothing <info>fits</info> "
2795 "your small frame perfectly." ) );
2796 }
2797 break;
2799 info.emplace_back( "DESCRIPTION", _( "* This clothing is <bad>oversized</bad> "
2800 "and does <bad>not fit</bad> you." ) );
2801 break;
2803 info.emplace_back( "DESCRIPTION",
2804 _( "* This clothing is hilariously <bad>oversized</bad> "
2805 "and does <bad>not fit</bad> your <info>abnormally "
2806 "small mutated anatomy</info>." ) );
2807 break;
2809 info.emplace_back( "DESCRIPTION",
2810 _( "* This clothing is <bad>normal sized</bad> and does "
2811 "<bad>not fit</info> your <info>abnormally large "
2812 "mutated anatomy</info>." ) );
2813 break;
2815 info.emplace_back( "DESCRIPTION",
2816 _( "* This clothing is <bad>normal sized</bad> and does "
2817 "<bad>not fit</bad> your <info>abnormally small "
2818 "mutated anatomy</info>." ) );
2819 break;
2821 info.emplace_back( "DESCRIPTION",
2822 _( "* This clothing is hilariously <bad>undersized</bad> "
2823 "and does <bad>not fit</bad> your <info>abnormally "
2824 "large mutated anatomy</info>." ) );
2825 break;
2827 info.emplace_back( "DESCRIPTION", _( "* This clothing is <bad>undersized</bad> "
2828 "and does <bad>not fit</bad> you." ) );
2829 break;
2830 default:
2831 break;
2832 }
2833 }
2834
2836 if( has_flag( flag_VARSIZE ) ) {
2837 std::string resize_str;
2838 if( has_flag( flag_FIT ) ) {
2839 switch( sizing_level ) {
2841 resize_str = _( "<info>can be upsized</info>" );
2842 break;
2844 resize_str = _( "<info>can be downsized</info>" );
2845 break;
2848 resize_str = _( "<bad>can not be downsized</bad>" );
2849 break;
2852 resize_str = _( "<bad>can not be upsized</bad>" );
2853 break;
2854 default:
2855 break;
2856 }
2857 if( !resize_str.empty() ) {
2858 std::string info_str = string_format( _( "* This clothing %s." ), resize_str );
2859 info.push_back( iteminfo( "DESCRIPTION", info_str ) );
2860 }
2861 } else {
2862 switch( sizing_level ) {
2864 resize_str = _( " and <info>upsized</info>" );
2865 break;
2867 resize_str = _( " and <info>downsized</info>" );
2868 break;
2871 resize_str = _( " but <bad>not downsized</bad>" );
2872 break;
2875 resize_str = _( " but <bad>not upsized</bad>" );
2876 break;
2877 default:
2878 break;
2879 }
2880 std::string info_str = string_format( _( "* This clothing <info>can be "
2881 "refitted</info>%s." ), resize_str );
2882 info.push_back( iteminfo( "DESCRIPTION", info_str ) );
2883 }
2884 } else {
2885 info.emplace_back( "DESCRIPTION", _( "* This clothing <bad>can not be refitted, "
2886 "upsized, or downsized</bad>." ) );
2887 }
2888 }
2889
2891 info.push_back( iteminfo( "DESCRIPTION",
2892 _( "* This item can be worn on <info>either side</info> of "
2893 "the body." ) ) );
2894 }
2895 if( ( is_power_armor() ) &&
2899 info.push_back( iteminfo( "DESCRIPTION",
2900 _( "* When worn with a power armor suit, it will "
2901 "<good>fully protect</good> you from "
2902 "<info>radiation</info>." ) ) );
2903 } else if( has_flag( flag_POWERARMOR_EXO ) ) {
2904 info.push_back( iteminfo( "DESCRIPTION",
2905 _( "* When worn with a power armor helmet, it will "
2906 "<good>fully protect</good> you from " "<info>radiation</info>." ) ) );
2907 }
2908 }
2909 }
2911 info.push_back( iteminfo( "DESCRIPTION",
2912 string_format( _( "* The film strip on the badge is %s." ),
2914 }
2915}
@ bp_head
Definition: bodypart.h:42
bool is_sided() const
Returns true if item is armor and can be worn on different sides of the body.
Definition: item.cpp:805
int irradiation
Definition: item.h:2207
bool is_power_armor() const
Whether this is a power armor item.
Definition: item.cpp:5811
sizing
Definition: item.h:2126
@ small_sized_small_char
@ human_sized_human_char
@ small_sized_human_char
@ human_sized_small_char
bool is_armor() const
Definition: item.cpp:6729
sizing get_sizing(const Character &, bool) const
Definition: item.cpp:1180
int get_encumber(const Character &) const
Returns the encumbrance value that this item has when worn by given player.
Definition: item.cpp:5817
bool covers(body_part bp) const
Whether this item (when worn) covers the given body part.
Definition: item.cpp:746
static const std::string flag_FIT("FIT")
static const std::string flag_HELMET_COMPAT("HELMET_COMPAT")
static const std::string flag_POWERARMOR_EXO("POWERARMOR_EXO")
static const itype_id itype_rad_badge("rad_badge")
static const std::string flag_VARSIZE("VARSIZE")
static const std::string flag_POWERARMOR_EXTERNAL("POWERARMOR_EXTERNAL")
std::string rad_badge_color(const int rad)
Definition: item.cpp:292
@ DESCRIPTION_FLAGS_POWERARMOR
@ DESCRIPTION_FLAGS_POWERARMOR_RADIATIONHINT
@ DESCRIPTION_FLAGS_HELMETCOMPAT

References _, big_sized_big_char, big_sized_human_char, big_sized_small_char, bp_head, covers(), DESCRIPTION_FLAGS_FITS, DESCRIPTION_FLAGS_HELMETCOMPAT, DESCRIPTION_FLAGS_POWERARMOR, DESCRIPTION_FLAGS_POWERARMOR_RADIATIONHINT, DESCRIPTION_FLAGS_SIDED, DESCRIPTION_FLAGS_VARSIZE, DESCRIPTION_IRRADIATION, flag_FIT(), flag_HELMET_COMPAT(), flag_POWERARMOR_EXO(), flag_POWERARMOR_EXTERNAL(), flag_VARSIZE(), get_avatar(), get_encumber(), get_sizing(), has_flag(), human_sized_big_char, human_sized_human_char, human_sized_small_char, info(), irradiation, is_armor(), is_power_armor(), is_sided(), itype_rad_badge, rad_badge_color(), small_sized_big_char, small_sized_human_char, small_sized_small_char, string_format(), iteminfo_query::test(), and typeId().

Referenced by final_info().

◆ armor_info()

void item::armor_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2552 of file item.cpp.

2554{
2555 if( !is_armor() ) {
2556 return;
2557 }
2558
2559 avatar &you = get_avatar();
2560 int encumbrance = get_encumber( you );
2561 const sizing sizing_level = get_sizing( you, encumbrance != 0 );
2562 const std::string space = " ";
2563 body_part_set covered_parts = get_covered_body_parts();
2564 bool covers_anything = covered_parts.any();
2565
2566 if( parts->test( iteminfo_parts::ARMOR_BODYPARTS ) ) {
2568 std::string coverage = _( "<bold>Covers</bold>: " );
2569 if( covers( bp_head ) ) {
2570 coverage += _( "The <info>head</info>. " );
2571 }
2572 if( covers( bp_eyes ) ) {
2573 coverage += _( "The <info>eyes</info>. " );
2574 }
2575 if( covers( bp_mouth ) ) {
2576 coverage += _( "The <info>mouth</info>. " );
2577 }
2578 if( covers( bp_torso ) ) {
2579 coverage += _( "The <info>torso</info>. " );
2580 }
2581
2582 if( is_sided() && ( covers( bp_arm_l ) || covers( bp_arm_r ) ) ) {
2583 coverage += _( "Either <info>arm</info>. " );
2584 } else if( covers( bp_arm_l ) && covers( bp_arm_r ) ) {
2585 coverage += _( "The <info>arms</info>. " );
2586 } else if( covers( bp_arm_l ) ) {
2587 coverage += _( "The <info>left arm</info>. " );
2588 } else if( covers( bp_arm_r ) ) {
2589 coverage += _( "The <info>right arm</info>. " );
2590 }
2591
2592 if( is_sided() && ( covers( bp_hand_l ) || covers( bp_hand_r ) ) ) {
2593 coverage += _( "Either <info>hand</info>. " );
2594 } else if( covers( bp_hand_l ) && covers( bp_hand_r ) ) {
2595 coverage += _( "The <info>hands</info>. " );
2596 } else if( covers( bp_hand_l ) ) {
2597 coverage += _( "The <info>left hand</info>. " );
2598 } else if( covers( bp_hand_r ) ) {
2599 coverage += _( "The <info>right hand</info>. " );
2600 }
2601
2602 if( is_sided() && ( covers( bp_leg_l ) || covers( bp_leg_r ) ) ) {
2603 coverage += _( "Either <info>leg</info>. " );
2604 } else if( covers( bp_leg_l ) && covers( bp_leg_r ) ) {
2605 coverage += _( "The <info>legs</info>. " );
2606 } else if( covers( bp_leg_l ) ) {
2607 coverage += _( "The <info>left leg</info>. " );
2608 } else if( covers( bp_leg_r ) ) {
2609 coverage += _( "The <info>right leg</info>. " );
2610 }
2611
2612 if( is_sided() && ( covers( bp_foot_l ) || covers( bp_foot_r ) ) ) {
2613 coverage += _( "Either <info>foot</info>. " );
2614 } else if( covers( bp_foot_l ) && covers( bp_foot_r ) ) {
2615 coverage += _( "The <info>feet</info>. " );
2616 } else if( covers( bp_foot_l ) ) {
2617 coverage += _( "The <info>left foot</info>. " );
2618 } else if( covers( bp_foot_r ) ) {
2619 coverage += _( "The <info>right foot</info>. " );
2620 }
2621
2622 if( !covers_anything ) {
2623 coverage += _( "<info>Nothing</info>." );
2624 }
2625
2626 info.push_back( iteminfo( "ARMOR", coverage ) );
2627 }
2628
2629 if( parts->test( iteminfo_parts::ARMOR_LAYER ) && covers_anything ) {
2630 std::string layering = _( "Layer: " );
2631 if( has_flag( flag_PERSONAL ) ) {
2632 layering += _( "<stat>Personal aura</stat>. " );
2633 } else if( has_flag( flag_SKINTIGHT ) ) {
2634 layering += _( "<stat>Close to skin</stat>. " );
2635 } else if( has_flag( flag_BELTED ) ) {
2636 layering += _( "<stat>Strapped</stat>. " );
2637 } else if( has_flag( flag_OUTER ) ) {
2638 layering += _( "<stat>Outer</stat>. " );
2639 } else if( has_flag( flag_WAIST ) ) {
2640 layering += _( "<stat>Waist</stat>. " );
2641 } else if( has_flag( flag_AURA ) ) {
2642 layering += _( "<stat>Outer aura</stat>. " );
2643 } else {
2644 layering += _( "<stat>Normal</stat>. " );
2645 }
2646
2647 info.push_back( iteminfo( "ARMOR", layering ) );
2648 }
2649
2650 if( parts->test( iteminfo_parts::ARMOR_COVERAGE ) && covers_anything ) {
2651 info.push_back( iteminfo( "ARMOR", _( "Coverage: " ), "<num>%",
2653 }
2654 if( parts->test( iteminfo_parts::ARMOR_WARMTH ) && covers_anything ) {
2655 info.push_back( iteminfo( "ARMOR", space + _( "Warmth: " ), get_warmth() ) );
2656 }
2657
2659
2660 if( parts->test( iteminfo_parts::ARMOR_ENCUMBRANCE ) && covers_anything ) {
2661 std::string format;
2662 if( has_flag( flag_FIT ) ) {
2663 format = _( "<num> <info>(fits)</info>" );
2664 } else if( has_flag( flag_VARSIZE ) && encumbrance ) {
2665 format = _( "<num> <bad>(poor fit)</bad>" );
2666 }
2667
2668 //If we have the wrong size, we do not fit so alert the player
2669 if( sizing_level == sizing::human_sized_small_char ) {
2670 format = _( "<num> <bad>(too big)</bad>" );
2671 } else if( sizing_level == sizing::big_sized_small_char ) {
2672 format = _( "<num> <bad>(huge!)</bad>" );
2673 } else if( sizing_level == sizing::small_sized_human_char ||
2674 sizing_level == sizing::human_sized_big_char ) {
2675 format = _( "<num> <bad>(too small)</bad>" );
2676 } else if( sizing_level == sizing::small_sized_big_char ) {
2677 format = _( "<num> <bad>(tiny!)</bad>" );
2678 }
2679
2680 info.push_back( iteminfo( "ARMOR", _( "<bold>Encumbrance</bold>: " ), format,
2682 encumbrance ) );
2683 if( !type->rigid ) {
2684 const int encumbrance_when_full =
2686 info.push_back( iteminfo( "ARMOR", space + _( "Encumbrance when full: " ), "",
2688 encumbrance_when_full ) );
2689 }
2690 }
2691
2692 int converted_storage_scale = 0;
2693 const double converted_storage = round_up( convert_volume( get_storage().value(),
2694 &converted_storage_scale ), 2 );
2695 if( parts->test( iteminfo_parts::ARMOR_STORAGE ) && converted_storage > 0 ) {
2696 const iteminfo::flags f = converted_storage_scale == 0 ? iteminfo::no_flags : iteminfo::is_decimal;
2697 info.push_back( iteminfo( "ARMOR", space + _( "Storage: " ),
2698 string_format( "<num> %s", volume_units_abbr() ),
2699 f, converted_storage ) );
2700 }
2701
2702 // Whatever the last entry was, we want a newline at this point
2703 info.back().bNewLine = true;
2704
2705 if( covers_anything ) {
2706 armor_protection_info( info, parts, batch, debug );
2707 }
2708
2709 const units::mass weight_bonus = get_weight_capacity_bonus();
2710 const float weight_modif = get_weight_capacity_modifier();
2711 if( weight_modif != 1 ) {
2712 std::string modifier;
2713 if( weight_modif < 1 ) {
2714 modifier = "<num><bad>x</bad>";
2715 } else {
2716 modifier = "<num><color_light_green>x</color>";
2717 }
2718 info.push_back( iteminfo( "ARMOR",
2719 _( "<bold>Weight capacity modifier</bold>: " ), modifier,
2720 iteminfo::no_newline | iteminfo::is_decimal, weight_modif ) );
2721 }
2722 if( weight_bonus != 0_gram ) {
2723 std::string bonus;
2724 if( weight_bonus < 0_gram ) {
2725 bonus = string_format( "<num> <bad>%s</bad>", weight_units() );
2726 } else {
2727 bonus = string_format( "<num> <color_light_green> %s</color>", weight_units() );
2728 }
2729 info.push_back( iteminfo( "ARMOR", _( "<bold>Weight capacity bonus</bold>: " ), bonus,
2731 convert_weight( weight_bonus ) ) );
2732 }
2733}
@ bp_foot_l
Definition: bodypart.h:51
@ bp_leg_r
Definition: bodypart.h:50
@ bp_eyes
Definition: bodypart.h:43
@ bp_hand_l
Definition: bodypart.h:47
@ bp_arm_l
Definition: bodypart.h:45
@ bp_leg_l
Definition: bodypart.h:49
@ bp_hand_r
Definition: bodypart.h:48
@ bp_torso
Definition: bodypart.h:41
@ bp_mouth
Definition: bodypart.h:44
@ bp_foot_r
Definition: bodypart.h:52
@ bp_arm_r
Definition: bodypart.h:46
bool any() const
Definition: bodypart.h:262
units::volume get_total_capacity() const
It returns the maximum volume of any contents, including liquids, ammo, magazines,...
Definition: item.cpp:8425
int get_encumber_when_containing(const Character &, const units::volume &contents_volume) const
Returns the encumbrance value that this item has when worn by given player, when containing a particu...
Definition: item.cpp:5845
units::mass get_weight_capacity_bonus() const
Returns the weight capacity bonus (islot_armor::weight_capacity_modifier) that this item provides whe...
Definition: item.cpp:5779
body_part_set get_covered_body_parts() const
Bitset of all covered body parts.
Definition: item.cpp:756
int get_warmth() const
Returns the warmth value that this item has when worn.
Definition: item.cpp:5943
int get_coverage() const
Returns the relative coverage that this item has when worn.
Definition: item.cpp:5925
float get_weight_capacity_modifier() const
Returns the weight capacity modifier (islot_armor::weight_capacity_modifier) that this item provides ...
Definition: item.cpp:5770
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&... args)
\rst Formats arguments and returns the result as a string.
Definition: fmtlib_core.h:2316
static const std::string flag_WAIST("WAIST")
static const std::string flag_BELTED("BELTED")
static const std::string flag_SKINTIGHT("SKINTIGHT")
static const std::string flag_OUTER("OUTER")
static const std::string flag_AURA("AURA")
static const std::string flag_PERSONAL("PERSONAL")
bool rigid
Definition: itype.h:959
const char * weight_units()
Create a units label for a weight value.
double convert_weight(const units::mass &weight)
Convert weight in grams to units defined by user (kg or lbs)

References _, body_part_set::any(), ARMOR_BODYPARTS, ARMOR_COVERAGE, ARMOR_ENCUMBRANCE, ARMOR_LAYER, armor_protection_info(), ARMOR_STORAGE, ARMOR_WARMTH, big_sized_small_char, bp_arm_l, bp_arm_r, bp_eyes, bp_foot_l, bp_foot_r, bp_hand_l, bp_hand_r, bp_head, bp_leg_l, bp_leg_r, bp_mouth, bp_torso, convert_volume(), convert_weight(), covers(), debug, flag_AURA(), flag_BELTED(), flag_FIT(), flag_OUTER(), flag_PERSONAL(), flag_SKINTIGHT(), flag_VARSIZE(), flag_WAIST(), format(), get_avatar(), get_coverage(), get_covered_body_parts(), get_encumber(), get_encumber_when_containing(), get_sizing(), get_storage(), get_total_capacity(), get_warmth(), get_weight_capacity_bonus(), get_weight_capacity_modifier(), has_flag(), human_sized_big_char, human_sized_small_char, info(), insert_separation_line(), is_armor(), iteminfo::is_decimal, is_sided(), iteminfo::lower_is_better, iteminfo::no_flags, iteminfo::no_newline, itype::rigid, round_up(), small_sized_big_char, small_sized_human_char, sign::space, string_format(), iteminfo_query::test(), type, volume_units_abbr(), and weight_units().

Referenced by info().

◆ armor_protection_info()

void item::armor_protection_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2509 of file item.cpp.

2512{
2513 if( !is_armor() && !is_pet_armor() ) {
2514 return;
2515 }
2516
2517 const std::string space = " ";
2518
2519 if( parts->test( iteminfo_parts::ARMOR_PROTECTION ) ) {
2520 info.push_back( iteminfo( "ARMOR", _( "<bold>Protection</bold>: Bash: " ), "",
2522 info.push_back( iteminfo( "ARMOR", space + _( "Cut: " ), "", iteminfo::no_newline, cut_resist() ) );
2523 info.push_back( iteminfo( "ARMOR", space + _( "Ballistic: " ), bullet_resist() ) );
2524 info.push_back( iteminfo( "ARMOR", space + _( "Acid: " ), "",
2526 info.push_back( iteminfo( "ARMOR", space + _( "Fire: " ), "",
2528 info.push_back( iteminfo( "ARMOR", space + _( "Environmental: " ),
2529 get_base_env_resist( *this ) ) );
2530 if( type->can_use( "GASMASK" ) || type->can_use( "DIVE_TANK" ) ) {
2531 info.push_back( iteminfo( "ARMOR",
2532 _( "<bold>Protection when active</bold>: " ) ) );
2533 info.push_back( iteminfo( "ARMOR", space + _( "Acid: " ), "",
2536 info.push_back( iteminfo( "ARMOR", space + _( "Fire: " ), "",
2539 info.push_back( iteminfo( "ARMOR", space + _( "Environmental: " ),
2541 }
2542
2543 if( damage() > 0 ) {
2544 info.push_back( iteminfo( "ARMOR",
2545 _( "Protection values are <bad>reduced by damage</bad> and "
2546 "you may be able to <info>improve them by repairing this "
2547 "item</info>." ) ) );
2548 }
2549 }
2550}
int bash_resist(bool to_self=false) const
Definition: item.cpp:6056
int fire_resist(bool to_self=false, int base_env_resist=0) const
Definition: item.cpp:6186
int acid_resist(bool to_self=false, int base_env_resist=0) const
Resistance against different damage types (damage_type).
Definition: item.cpp:6152
int bullet_resist(bool to_self=false) const
Definition: item.cpp:6123
int get_base_env_resist_w_filter() const
Returns the base resistance to environmental effects if an item (for example a gas mask) requires a g...
Definition: item.cpp:5802
int cut_resist(bool to_self=false) const
Definition: item.cpp:6084
int damage() const
How much damage has the item sustained?
Definition: item.cpp:699
static int get_base_env_resist(const item &it)
Definition: item.cpp:1223
bool can_use(const std::string &iuse_name) const
Definition: itype.cpp:161

References _, acid_resist(), ARMOR_PROTECTION, bash_resist(), bullet_resist(), itype::can_use(), cut_resist(), damage(), fire_resist(), get_base_env_resist(), get_base_env_resist_w_filter(), get_env_resist(), info(), is_armor(), is_pet_armor(), iteminfo::no_newline, sign::space, iteminfo_query::test(), and type.

Referenced by animal_armor_info(), and armor_info().

◆ attack_cost()

int item::attack_cost ( ) const

Base number of moves (Creature::moves) that a single melee attack with this items takes.

The actual time depends heavily on the attacker, see melee.cpp.

Definition at line 5206 of file item.cpp.

5207{
5208 int base = 65 + ( volume() / 62.5_ml + weight() / 60_gram ) / count();
5210 return std::max( 0, base + bonus );
5211}
double bonus_from_enchantments_wielded(double base, enchant_vals::mod value, bool round=false) const
Calculate bonus from enchantments that affect this item only, assume it's wielded and all enchantment...
Definition: item.cpp:7031
units::mass weight(bool include_contents=true, bool integral=false) const
Definition: item.cpp:4983
units::volume volume(bool integral=false) const
Total volume of an item accounting for all contained/integrated items NOTE: Result is rounded up to n...
Definition: item.cpp:5129

References bonus_from_enchantments_wielded(), count(), enchant_vals::ITEM_ATTACK_COST, volume(), and weight().

Referenced by Character::attack_cost(), combat_info(), Character::melee_attack(), npc::move_to(), smash(), and ranged::throw_cost().

◆ average_dps()

double item::average_dps ( const player guy) const

return the average dps of the weapon against evaluation monsters

Definition at line 1451 of file item.cpp.

1452{
1453 double dmg_count = 0.0;
1454 const std::map<std::string, double> &dps_data = dps( false, true, guy );
1455 for( const std::pair<const std::string, double> &dps_entry : dps_data ) {
1456 dmg_count += dps_entry.second;
1457 }
1458 return dmg_count / dps_data.size();
1459}
std::map< std::string, double > dps(bool for_display, bool for_calc, const player &guy) const
calculate effective dps against a stock set of monsters.
Definition: item.cpp:1431

References dps().

Referenced by npc_ai::melee_value().

◆ base_damage_melee()

damage_instance item::base_damage_melee ( ) const

All damage types this item deals when used in melee (no skill modifiers etc.

applied).

Definition at line 5269 of file item.cpp.

5270{
5271 // TODO: Caching
5273 for( size_t i = DT_NULL + 1; i < NUM_DT; i++ ) {
5274 damage_type dt = static_cast<damage_type>( i );
5275 int dam = damage_melee( dt );
5276 if( dam > 0 ) {
5277 ret.add_damage( dt, dam );
5278 }
5279 }
5280
5281 return ret;
5282}
int damage_melee(damage_type dt) const
Damage of given type caused when this item is used as melee weapon.
Definition: item.cpp:5213
damage_type
Definition: damage.h:20
@ DT_NULL
Definition: damage.h:21
@ NUM_DT
Definition: damage.h:32

References damage_melee(), DT_NULL, NUM_DT, and cata::hash64_detail::ret.

◆ base_damage_thrown()

damage_instance item::base_damage_thrown ( ) const

All damage types this item deals when thrown (no skill modifiers etc.

applied).

Definition at line 5284 of file item.cpp.

5285{
5286 // TODO: Create a separate cache for individual items (for modifiers like diamond etc.)
5287 return type->thrown_damage;
5288}
damage_instance thrown_damage
Base damage output when thrown.
Definition: itype.h:964

References itype::thrown_damage, and type.

Referenced by ranged::throw_item().

◆ base_volume()

units::volume item::base_volume ( ) const

Simplified, faster volume check for when processing time is important and exact volume is not.

NOTE: Result is rounded up to next nearest milliliter when working with stackable (count_by_charges) items that have fractional volume per charge. If trying to determine how many of an item can fit in a given space, charges_per_volume should be used instead.

Definition at line 5101 of file item.cpp.

5102{
5103 if( is_null() ) {
5104 return 0_ml;
5105 }
5106 if( is_corpse() ) {
5107 return corpse_volume( corpse );
5108 }
5109
5110 if( is_craft() ) {
5111 units::volume ret = 0_ml;
5112 for( const item &it : components ) {
5113 ret += it.base_volume();
5114 }
5115 return ret;
5116 }
5117
5118 if( count_by_charges() ) {
5119 if( type->volume % type->stack_size == 0_ml ) {
5120 return type->volume / type->stack_size;
5121 } else {
5122 return type->volume / type->stack_size + 1_ml;
5123 }
5124 }
5125
5126 return type->volume;
5127}
bool count_by_charges() const
Definition: item.cpp:6030
units::volume corpse_volume(const mtype *corpse) const
Volume check for corpses, helper for base_volume().
Definition: item.cpp:5079
bool is_craft() const
Definition: item.cpp:6948
bool is_corpse() const
Whether this is a corpse item.
Definition: item.cpp:6645
int stack_size
Number of items per above volume for count_by_charges items.
Definition: itype.h:950
units::volume volume
Space occupied by items of this type CAUTION: value given is for a default-sized stack.
Definition: itype.h:942

References components, corpse, corpse_volume(), count_by_charges(), is_corpse(), is_craft(), is_null(), cata::hash64_detail::ret, itype::stack_size, type, and itype::volume.

Referenced by burn(), flammable(), and simulate_burn().

◆ bash_resist()

int item::bash_resist ( bool  to_self = false) const

Definition at line 6056 of file item.cpp.

6057{
6058 if( is_null() ) {
6059 return 0;
6060 }
6061
6062 float resist = 0;
6064 int eff_thickness = 1;
6065
6066 // base resistance
6067 // Don't give reinforced items +armor, just more resistance to ripping
6068 const int dmg = damage_level( 4 );
6069 const int eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 );
6070 eff_thickness = std::max( 1, get_thickness() - eff_damage );
6071
6072 const std::vector<const material_type *> mat_types = made_of_types();
6073 if( !mat_types.empty() ) {
6074 for( const material_type *mat : mat_types ) {
6075 resist += mat->bash_resist();
6076 }
6077 // Average based on number of materials.
6078 resist /= mat_types.size();
6079 }
6080
6081 return std::lround( ( resist * eff_thickness ) + mod );
6082}
int get_thickness() const
Returns the islot_armor::thickness value, or 0 for non-armor.
Definition: item.cpp:5934
int damage_level(int max) const
Scale item damage to the given number of levels.
Definition: item.cpp:704
@ clothing_mod_type_bash
Definition: clothing_mod.h:19
STL namespace.

References clothing_mod_type_bash, damage_level(), get_clothing_mod_val(), get_thickness(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), and sew_advanced_actor::use().

◆ basic_info()

void item::basic_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 1461 of file item.cpp.

1463{
1465 info.emplace_back( "BASE", string_format( _( "<stat>Origin: %s</stat>" ),
1466 enumerate_as_string( type->src.begin(),
1467 type->src.end(), []( const std::pair<itype_id, mod_id> &source ) {
1468 return string_format( "'%s'", source.second->name() );
1471 }
1473 info.emplace_back( "BASE", colorize( string_format( "[%s]", type->get_id() ), c_light_blue ) );
1475 }
1476
1477 const std::string space = " ";
1478 if( parts->test( iteminfo_parts::BASE_MATERIAL ) ) {
1479 const std::vector<const material_type *> mat_types = made_of_types();
1480 if( !mat_types.empty() ) {
1481 const std::string material_list = enumerate_as_string( mat_types.begin(), mat_types.end(),
1482 []( const material_type * material ) {
1483 return string_format( "<stat>%s</stat>", material->name() );
1485 info.push_back( iteminfo( "BASE", string_format( _( "Material: %s" ), material_list ) ) );
1486 }
1487 }
1488 if( parts->test( iteminfo_parts::BASE_VOLUME ) ) {
1489 int converted_volume_scale = 0;
1490 const double converted_volume = round_up( convert_volume( volume().value(),
1491 &converted_volume_scale ) * batch, 3 );
1493 if( converted_volume_scale != 0 ) {
1495 }
1496 info.push_back( iteminfo( "BASE", _( "Volume: " ),
1497 string_format( "<num> %s", volume_units_abbr() ),
1498 f, converted_volume ) );
1499 }
1500 if( parts->test( iteminfo_parts::BASE_WEIGHT ) ) {
1501 info.push_back( iteminfo( "BASE", space + _( "Weight: " ),
1502 string_format( "<num> %s", weight_units() ),
1504 convert_weight( weight() ) * batch ) );
1505 }
1506 if( !owner.is_null() ) {
1507 info.push_back( iteminfo( "BASE", string_format( _( "Owner: %s" ),
1508 _( get_owner_name() ) ) ) );
1509 }
1510 if( parts->test( iteminfo_parts::BASE_CATEGORY ) ) {
1511 info.push_back( iteminfo( "BASE", _( "Category: " ),
1512 "<header>" + get_category().name() + "</header>" ) );
1513 }
1514 if( !type->weapon_category.empty() && parts->test( iteminfo_parts::WEAPON_CATEGORY ) ) {
1515 const std::string weapon_categories = enumerate_as_string( type->weapon_category.begin(),
1516 type->weapon_category.end(), [&]( const weapon_category_id & elem ) {
1517 return elem->name().translated();
1519 info.push_back( iteminfo( "BASE", _( "Weapon Category: " ),
1520 "<header>" + weapon_categories + "</header>" ) );
1521 }
1522
1523 if( parts->test( iteminfo_parts::DESCRIPTION ) ) {
1525 const std::map<std::string, std::string>::const_iterator idescription =
1526 item_vars.find( "description" );
1527 const std::optional<translation> snippet = SNIPPET.get_snippet_by_id( snip_id );
1528 if( snippet.has_value() ) {
1529 // Just use the dynamic description
1530 info.push_back( iteminfo( "DESCRIPTION", snippet.value().translated() ) );
1531 } else if( idescription != item_vars.end() ) {
1532 info.push_back( iteminfo( "DESCRIPTION", idescription->second ) );
1533 } else {
1534 if( has_flag( "MAGIC_FOCUS" ) ) {
1535 info.push_back( iteminfo( "DESCRIPTION",
1536 _( "This item is a <info>magical focus</info>. "
1537 "You can cast spells with it in your hand." ) ) );
1538 }
1539 if( is_craft() ) {
1540 const std::string desc = _( "This is an in progress %s. "
1541 "It is %d percent complete." );
1542 const int percent_progress = item_counter / 100000;
1543 info.push_back( iteminfo( "DESCRIPTION", string_format( desc,
1544 craft_data_->making->result_name(),
1545 percent_progress ) ) );
1546 } else {
1547 info.push_back( iteminfo( "DESCRIPTION", type->description.translated() ) );
1548 }
1549 }
1551 }
1552
1554
1555 if( parts->test( iteminfo_parts::BASE_REQUIREMENTS ) ) {
1556 // Display any minimal stat or skill requirements for the item
1557 std::vector<std::string> req;
1558 if( get_min_str() > 0 ) {
1559 avatar &viewer = get_avatar();
1560 if( has_flag( flag_STR_DRAW ) && ranged::get_str_draw_penalty( *this, viewer ) < 1.0f ) {
1561 if( ranged::get_str_draw_penalty( *this, viewer ) < 0.5f ) {
1562 req.push_back( string_format( _( "%s %d <color_magenta>(Can't use!)</color>" ), _( "strength" ),
1563 get_min_str() ) );
1564 } else if( ranged::get_str_draw_penalty( *this, viewer ) < 0.75f ) {
1565 req.push_back( string_format( "%s %d <color_red>(Damage/Range 0.5x, Dispersion 2.0x)</color>",
1566 _( "strength" ), get_min_str() ) );
1567 } else {
1568 req.push_back( string_format( "%s %d <color_yellow>(Damage/Range 0.75x)</color>", _( "strength" ),
1569 get_min_str() ) );
1570 }
1571 } else {
1572 req.push_back( string_format( "%s %d", _( "strength" ), get_min_str() ) );
1573 }
1574 }
1575 if( type->min_dex > 0 ) {
1576 req.push_back( string_format( "%s %d", _( "dexterity" ), type->min_dex ) );
1577 }
1578 if( type->min_int > 0 ) {
1579 req.push_back( string_format( "%s %d", _( "intelligence" ), type->min_int ) );
1580 }
1581 if( type->min_per > 0 ) {
1582 req.push_back( string_format( "%s %d", _( "perception" ), type->min_per ) );
1583 }
1584 for( const std::pair<const skill_id, int> sk : sorted_lex( type->min_skills ) ) {
1585 req.push_back( string_format( "%s %d", skill_id( sk.first )->name(), sk.second ) );
1586 }
1587 if( !req.empty() ) {
1588 info.emplace_back( "BASE", _( "<bold>Minimum requirements</bold>:" ) );
1589 info.emplace_back( "BASE", enumerate_as_string( req ) );
1591 }
1592 }
1593
1594 if( has_var( "contained_name" ) && parts->test( iteminfo_parts::BASE_CONTENTS ) ) {
1595 info.push_back( iteminfo( "BASE", string_format( _( "Contains: %s" ),
1596 get_var( "contained_name" ) ) ) );
1597 }
1598 if( count_by_charges() && !is_food() && !is_medication() &&
1599 parts->test( iteminfo_parts::BASE_AMOUNT ) ) {
1600 info.push_back( iteminfo( "BASE", _( "Amount: " ), "<num>", iteminfo::no_flags,
1601 charges * batch ) );
1602 }
1603 if( debug && parts->test( iteminfo_parts::BASE_DEBUG ) ) {
1604 if( g != nullptr ) {
1605 info.push_back( iteminfo( "BASE", string_format( "itype_id: %s",
1606 typeId().c_str() ) ) );
1607 info.push_back( iteminfo( "BASE", _( "age (hours): " ), "", iteminfo::lower_is_better,
1608 to_hours<int>( age() ) ) );
1609 info.push_back( iteminfo( "BASE", _( "charges: " ), "", iteminfo::lower_is_better,
1610 charges ) );
1611 info.push_back( iteminfo( "BASE", _( "damage: " ), "", iteminfo::lower_is_better,
1612 damage_ ) );
1613 info.push_back( iteminfo( "BASE", _( "active: " ), "", iteminfo::lower_is_better,
1614 active ) );
1615 info.push_back( iteminfo( "BASE", _( "burn: " ), "", iteminfo::lower_is_better,
1616 burnt ) );
1617 const std::string tags_listed = enumerate_as_string( item_tags, enumeration_conjunction::none );
1618 info.push_back( iteminfo( "BASE", string_format( _( "tags: %s" ), tags_listed ) ) );
1619 for( auto const &imap : item_vars ) {
1620 info.push_back( iteminfo( "BASE",
1621 string_format( _( "item var: %s, %s" ), imap.first,
1622 imap.second ) ) );
1623 }
1624
1625 const item *food = get_food();
1626 if( food && food->goes_bad() ) {
1627 info.push_back( iteminfo( "BASE", _( "age (turns): " ),
1629 to_turns<int>( food->age() ) ) );
1630 info.push_back( iteminfo( "BASE", _( "rot (turns): " ),
1632 to_turns<int>( food->rot ) ) );
1633 info.push_back( iteminfo( "BASE", space + _( "max rot (turns): " ),
1635 to_turns<int>( food->get_shelf_life() ) ) );
1636 info.push_back( iteminfo( "BASE", _( "last rot: " ),
1638 to_turn<int>( food->last_rot_check ) ) );
1639 }
1640 }
1641 }
1642}
bool display_object_ids
Display internal IDs for items, furniture, terrain and monsters.
bool display_mod_source
Display mod source for items, furniture, terrain and monsters.
double get_var(const std::string &name, double default_value) const
Definition: item.cpp:1033
int burnt
Definition: item.h:2203
int get_min_str() const
Definition: item.cpp:10073
bool has_var(const std::string &name) const
Whether the variable is defined at all.
Definition: item.cpp:1078
time_duration age() const
Definition: item.cpp:10034
time_duration rot
Accumulated rot, expressed as time the item has been in standard temperature.
Definition: item.h:2223
faction_id owner
Definition: item.h:2229
bool is_medication() const
Definition: item.cpp:6623
time_duration get_shelf_life() const
Get the shelf life of the item.
Definition: item.cpp:5544
int damage_
Definition: item.h:2232
item * get_food()
Definition: item.cpp:6667
const item_category & get_category() const
Definition: item.cpp:8707
FlagsSetType item_tags
Definition: item.h:2167
std::string get_owner_name() const
Definition: item.cpp:1264
std::optional< translation > get_snippet_by_id(const snippet_id &id) const
Returns the snippet referenced by the id, or std::nullopt if there is no snippet with such id.
std::string translated(int num=1) const
Returns raw string if no translation is needed, otherwise returns the translated string.
std::string colorize(const std::string &text, const nc_color &color)
Definition: color.cpp:669
#define c_light_blue
Definition: color.h:29
std::unique_ptr< game > g
Definition: game.cpp:283
static const std::string flag_STR_DRAW("STR_DRAW")
std::vector< material_type > material_list
Definition: material.h:23
float get_str_draw_penalty(const item &it, const Character &p)
Penalties potentially incurred by STR_DRAW weapons.
Definition: ranged.cpp:1022
std::string enumerate_as_string(const _Container &values, enumeration_conjunction conj=enumeration_conjunction::and_)
Definition: output.h:637
std::vector< std::pair< K, V > > sorted_lex(Col col)
Returns vector sorted by lexicographic order of string_id.
@ is_three_decimal
Print as decimal with three points of precision.
Definition: item.h:145
int min_dex
Definition: itype.h:906
std::set< weapon_category_id > weapon_category
Definition: itype.h:873
int min_int
Definition: itype.h:907
int min_per
Definition: itype.h:908
translation description
Definition: itype.h:876
std::map< skill_id, int > min_skills
Definition: itype.h:904
std::vector< std::pair< itype_id, mod_id > > src
Definition: itype.h:809

References _, active, age(), arrow, BASE_AMOUNT, BASE_CATEGORY, BASE_CONTENTS, BASE_DEBUG, BASE_ID, BASE_MATERIAL, BASE_MOD_SRC, BASE_REQUIREMENTS, BASE_VOLUME, BASE_WEIGHT, burnt, c_light_blue, charges, colorize(), convert_volume(), convert_weight(), count_by_charges(), craft_data_, damage_, debug, DESCRIPTION, itype::description, display_mod_source, display_object_ids, enumerate_as_string(), flag_STR_DRAW(), g, get_avatar(), get_category(), get_food(), itype::get_id(), get_min_str(), get_owner_name(), get_shelf_life(), snippet_library::get_snippet_by_id(), ranged::get_str_draw_penalty(), get_var(), goes_bad(), has_flag(), has_var(), info(), insert_separation_line(), is_craft(), iteminfo::is_decimal, is_food(), is_medication(), string_id< T >::is_null(), iteminfo::is_three_decimal, item_counter, item_tags, item_vars, last_rot_check, iteminfo::lower_is_better, made_of_types(), itype::min_dex, itype::min_int, itype::min_per, itype::min_skills, om_direction::name(), iteminfo::no_flags, iteminfo::no_newline, none, owner, rot, round_up(), skill_id, snip_id, SNIPPET, sorted_lex(), sign::space, itype::src, string_format(), iteminfo_query::test(), translation::translated(), type, typeId(), volume(), volume_units_abbr(), WEAPON_CATEGORY, itype::weapon_category, weight(), and weight_units().

Referenced by info().

◆ battery_info()

void item::battery_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3082 of file item.cpp.

3084{
3085 if( !is_battery() ) {
3086 return;
3087 }
3088
3089 std::string info_string;
3090 if( type->battery->max_capacity < 1_kJ ) {
3091 info_string = string_format( _( "<bold>Capacity</bold>: %dJ" ),
3092 to_joule( type->battery->max_capacity ) );
3093 } else if( type->battery->max_capacity >= 1_kJ ) {
3094 info_string = string_format( _( "<bold>Capacity</bold>: %dkJ" ),
3095 to_kilojoule( type->battery->max_capacity ) );
3096 }
3098 info.emplace_back( "BATTERY", info_string );
3099}
bool is_battery() const
Definition: item.cpp:6587
std::string info_string() const
As info, but as a string rather than a vector of properties.
Definition: item.cpp:4086
constexpr value_type to_joule(const quantity< value_type, energy_in_joule_tag > &v)
Definition: units_energy.h:40
cata::value_ptr< islot_battery > battery
Definition: itype.h:830

References _, itype::battery, info(), info_string(), insert_separation_line(), is_battery(), string_format(), units::to_joule(), units::to_kilojoule(), and type.

Referenced by info().

◆ bionic_info()

void item::bionic_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3295 of file item.cpp.

3297{
3298 if( !is_bionic() ) {
3299 return;
3300 }
3301
3302 // TODO: Unhide when enforcing limits
3303 if( get_option < bool >( "CBM_SLOTS_ENABLED" )
3305 info.push_back( iteminfo( "DESCRIPTION", list_occupied_bps( type->bionic->id,
3306 _( "This bionic is installed in the following body "
3307 "part(s):" ) ) ) );
3308 }
3310
3311 const bionic_id bid = type->bionic->id;
3312 const std::vector<itype_id> &fuels = bid->fuel_opts;
3313 if( !fuels.empty() ) {
3314 const int &fuel_numb = fuels.size();
3315
3316 info.push_back( iteminfo( "DESCRIPTION",
3317 vgettext( "* This bionic can produce power from the following fuel: ",
3318 "* This bionic can produce power from the following fuels: ",
3319 fuel_numb ) + enumerate_as_string( fuels.begin(),
3320 fuels.end(), []( const itype_id & id ) -> std::string { return "<info>" + id->nname( 1 ) + "</info>"; } ) ) );
3321 }
3322
3324
3325 if( bid->capacity > 0_J ) {
3326 info.push_back( iteminfo( "CBM", _( "<bold>Power Capacity</bold>:" ), _( " <num> J" ),
3328 units::to_joule( bid->capacity ) ) );
3329 }
3330
3332
3333 if( !bid->encumbrance.empty() ) {
3334 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Encumbrance</bold>: " ),
3336 for( const std::pair< const bodypart_str_id, int > element : sorted_lex( bid->encumbrance ) ) {
3337 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3338 " <num> ", iteminfo::no_newline, element.second ) );
3339 }
3340 }
3341
3342 if( !bid->env_protec.empty() ) {
3343 info.push_back( iteminfo( "DESCRIPTION",
3344 bid->activated ? _( "<bold>Environmental Protection (activated)</bold>: " ) :
3345 _( "<bold>Environmental Protection</bold>: " ),
3347 for( const std::pair< const bodypart_str_id, int > element : sorted_lex( bid->env_protec ) ) {
3348 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3349 " <num> ", iteminfo::no_newline, element.second ) );
3350 }
3351 }
3352
3353 if( !bid->bash_protec.empty() ) {
3354 info.push_back( iteminfo( "DESCRIPTION",
3355 _( "<bold>Bash Protection</bold>: " ),
3357 for( const std::pair< const bodypart_str_id, int > element : sorted_lex( bid->bash_protec ) ) {
3358 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3359 " <num> ", iteminfo::no_newline, element.second ) );
3360 }
3361 }
3362
3363 if( !bid->cut_protec.empty() ) {
3364 info.push_back( iteminfo( "DESCRIPTION",
3365 _( "<bold>Cut Protection</bold>: " ),
3367 for( const std::pair< const bodypart_str_id, int > element : sorted_lex( bid->cut_protec ) ) {
3368 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3369 " <num> ", iteminfo::no_newline, element.second ) );
3370 }
3371 }
3372
3373 if( !bid->bullet_protec.empty() ) {
3374 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Ballistic Protection</bold>: " ),
3376 for( const auto &element : bid->bullet_protec ) {
3377 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3378 " <num> ", iteminfo::no_newline, element.second ) );
3379 }
3380 }
3381
3382 if( !bid->stat_bonus.empty() ) {
3383 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Stat Bonus</bold>: " ),
3385 for( const auto &element : bid->stat_bonus ) {
3386 info.push_back( iteminfo( "CBM", get_stat_name( element.first ), " <num> ",
3387 iteminfo::no_newline, element.second ) );
3388 }
3389 }
3390
3391 const units::mass weight_bonus = bid->weight_capacity_bonus;
3392 const float weight_modif = bid->weight_capacity_modifier;
3393 if( weight_modif != 1 ) {
3394 std::string modifier;
3395 if( weight_modif < 1 ) {
3396 modifier = "<num><bad>x</bad>";
3397 } else {
3398 modifier = "<num><color_light_green>x</color>";
3399 }
3400 info.push_back( iteminfo( "CBM",
3401 _( "<bold>Weight capacity modifier</bold>: " ), modifier,
3403 weight_modif ) );
3404 }
3405 if( weight_bonus != 0_gram ) {
3406 std::string bonus;
3407 if( weight_bonus < 0_gram ) {
3408 bonus = string_format( "<num> <bad>%s</bad>", weight_units() );
3409 } else {
3410 bonus = string_format( "<num> <color_light_green>%s</color>", weight_units() );
3411 }
3412 info.push_back( iteminfo( "CBM", _( "<bold>Weight capacity bonus</bold>: " ), bonus,
3414 convert_weight( weight_bonus ) ) );
3415 }
3416}
std::string list_occupied_bps(const bionic_id &bio_id, const std::string &intro, const bool each_bp_on_new_line)
Definition: bionics.cpp:2544
std::string body_part_name_as_heading(body_part bp, int number)
Returns the name of the body parts in a context where the name is used as a heading or title e....
Definition: bodypart.cpp:343
std::string get_stat_name(character_stat Stat)
Get translated name of a stat.
Definition: character.cpp:7750
bool is_bionic() const
Definition: item.cpp:6577
std::map< bodypart_str_id, int > cut_protec
Amount of cut protection offered by this bionic.
Definition: bionics.h:88
units::energy capacity
Power bank size.
Definition: bionics.h:49
bool activated
Is true if a bionic is an active instead of a passive bionic.
Definition: bionics.h:53
std::map< character_stat, int > stat_bonus
Map of stats and their corresponding bonuses passively granted by a bionic.
Definition: bionics.h:63
std::vector< itype_id > fuel_opts
Fuel types that can be used by this bionic.
Definition: bionics.h:67
float weight_capacity_modifier
Factor modifiying weight capacity.
Definition: bionics.h:59
units::mass weight_capacity_bonus
Bonus to weight capacity.
Definition: bionics.h:61
std::map< bodypart_str_id, int > encumbrance
Body part encumbered by this bionic, mapped to the amount of encumbrance caused.
Definition: bionics.h:99
std::map< bodypart_str_id, int > bullet_protec
Amount of bullet protection offered by this bionic.
Definition: bionics.h:90
std::map< bodypart_str_id, int > bash_protec
Amount of bash protection offered by this bionic.
Definition: bionics.h:86
std::map< bodypart_str_id, int > env_protec
Amount of environemental protection offered by this bionic.
Definition: bionics.h:84
cata::value_ptr< islot_bionic > bionic
Definition: itype.h:831
const char * vgettext(const char *msgid, const char *msgid_plural, size_t n)

References _, bionic_data::activated, bionic_data::bash_protec, itype::bionic, body_part_name_as_heading(), bionic_data::bullet_protec, bionic_data::capacity, convert_weight(), bionic_data::cut_protec, DESCRIPTION_CBM_SLOTS, bionic_data::encumbrance, enumerate_as_string(), bionic_data::env_protec, bionic_data::fuel_opts, get_stat_name(), info(), insert_separation_line(), is_bionic(), iteminfo::is_decimal, list_occupied_bps(), iteminfo::no_newline, sorted_lex(), bionic_data::stat_bonus, string_format(), iteminfo_query::test(), units::to_joule(), type, vgettext(), bionic_data::weight_capacity_bonus, bionic_data::weight_capacity_modifier, and weight_units().

Referenced by final_info().

◆ birthday()

◆ bonus_from_enchantments()

double item::bonus_from_enchantments ( const Character owner,
double  base,
enchant_vals::mod  value,
bool  round = false 
) const

Calculate bonus from enchantments that affect this item only.

Definition at line 7012 of file item.cpp.

7014{
7015 double add = 0.0;
7016 double mul = 0.0;
7017 for( const enchantment &ench : get_enchantments() ) {
7018 if( ench.is_active( owner, *this ) ) {
7019 add += ench.get_value_add( value );
7020 mul += ench.get_value_multiply( value );
7021 }
7022 }
7023 // TODO: this part duplicates enchantment::calc_bonus()
7024 double ret = add + base * mul;
7025 if( round ) {
7026 ret = trunc( ret );
7027 }
7028 return ret;
7029}
const std::vector< enchantment > & get_enchantments() const
Definition: item.cpp:7003
type add(type dir1, type dir2)
Returns a sum of two numbers.
Definition: overmap.cpp:4195

References om_direction::add(), get_enchantments(), owner, and cata::hash64_detail::ret.

Referenced by item_armor_enchantment_adjust().

◆ bonus_from_enchantments_wielded()

double item::bonus_from_enchantments_wielded ( double  base,
enchant_vals::mod  value,
bool  round = false 
) const

Calculate bonus from enchantments that affect this item only, assume it's wielded and all enchantments' conditions are satisfied.

Definition at line 7031 of file item.cpp.

7033{
7034 double add = 0.0;
7035 double mul = 0.0;
7036 for( const enchantment &ench : get_enchantments() ) {
7037 if( ench.is_active_when_wielded() ) {
7038 add += ench.get_value_add( value );
7039 mul += ench.get_value_multiply( value );
7040 }
7041 }
7042 // TODO: this part duplicates enchantment::calc_bonus()
7043 double ret = add + base * mul;
7044 if( round ) {
7045 ret = trunc( ret );
7046 }
7047 return ret;
7048}

References om_direction::add(), get_enchantments(), and cata::hash64_detail::ret.

Referenced by attack_cost(), and damage_melee().

◆ book_info()

void item::book_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2917 of file item.cpp.

2919{
2920 if( !is_book() ) {
2921 return;
2922 }
2923
2924 Character &character = get_player_character();
2925
2927 const islot_book &book = *type->book;
2928 // Some things about a book you CAN tell by it's cover.
2929 if( !book.skill && !type->can_use( "MA_MANUAL" ) && parts->test( iteminfo_parts::BOOK_SUMMARY ) ) {
2930 info.push_back( iteminfo( "BOOK", _( "Just for fun." ) ) );
2931 }
2932 if( type->can_use( "MA_MANUAL" ) && parts->test( iteminfo_parts::BOOK_SUMMARY ) ) {
2933 info.push_back( iteminfo( "BOOK",
2934 _( "Some sort of <info>martial arts training "
2935 "manual</info>." ) ) );
2936 const matype_id style_to_learn = martial_art_learned_from( *type );
2937 info.push_back( iteminfo( "BOOK",
2938 string_format( _( "You can learn <info>%s</info> style "
2939 "from it." ), style_to_learn->name ) ) );
2940 info.push_back( iteminfo( "BOOK",
2941 string_format( _( "This fighting style is <info>%s</info> "
2942 "to learn." ),
2943 martialart_difficulty( style_to_learn ) ) ) );
2944 info.push_back( iteminfo( "BOOK",
2945 string_format( _( "It'd be easier to master if you'd have "
2946 "skill expertise in <info>%s</info>." ),
2947 style_to_learn->primary_skill->name() ) ) );
2948 }
2949 if( book.req == 0 && parts->test( iteminfo_parts::BOOK_REQUIREMENTS_BEGINNER ) ) {
2950 info.push_back( iteminfo( "BOOK", _( "It can be <info>understood by "
2951 "beginners</info>." ) ) );
2952 }
2953 avatar &you = get_avatar();
2954 if( !you.has_identified( typeId() ) && parts->test( iteminfo_parts::BOOK_UNREAD ) ) {
2955 info.push_back( iteminfo( "BOOK",
2956 _( "You have <info>never read</info> this book." ) ) );
2957 }
2958 if( book.skill ) {
2959 const SkillLevel &skill = you.get_skill_level_object( book.skill );
2960 if( skill.can_train() && parts->test( iteminfo_parts::BOOK_SKILLRANGE_MAX ) ) {
2961 const std::string skill_name = book.skill->name();
2962 std::string fmt = string_format( _( "Can bring your <info>%s skill to</info> "
2963 "<num>." ), skill_name );
2964 info.push_back( iteminfo( "BOOK", "", fmt, iteminfo::no_flags, book.level ) );
2965 fmt = string_format( _( "Your current <stat>%s skill</stat> is <num>." ),
2966 skill_name );
2967 info.push_back( iteminfo( "BOOK", "", fmt, iteminfo::no_flags, skill.level() ) );
2968 }
2969
2970 if( book.req != 0 && parts->test( iteminfo_parts::BOOK_SKILLRANGE_MIN ) ) {
2971 const std::string fmt = string_format(
2972 _( "<info>Requires %s level</info> <num> to "
2973 "understand." ), book.skill.obj().name() );
2974 info.push_back( iteminfo( "BOOK", "", fmt,
2976 }
2977 }
2978
2979 if( book.intel != 0 && parts->test( iteminfo_parts::BOOK_REQUIREMENTS_INT ) ) {
2980 info.push_back( iteminfo( "BOOK", "",
2981 _( "Requires <info>intelligence of</info> <num> to easily "
2982 "read." ), iteminfo::lower_is_better, book.intel ) );
2983 }
2984 if( character_funcs::get_book_fun_for( character, *this ) != 0 &&
2986 info.push_back( iteminfo( "BOOK", "",
2987 _( "Reading this book affects your morale by <num>" ),
2989 }
2991 std::string fmt = vgettext(
2992 "A chapter of this book takes <num> <info>minute to "
2993 "read</info>.",
2994 "A chapter of this book takes <num> <info>minutes to "
2995 "read</info>.", book.time );
2996 if( type->use_methods.count( "MA_MANUAL" ) ) {
2997 fmt = vgettext(
2998 "<info>A training session</info> with this book takes "
2999 "<num> <info>minute</info>.",
3000 "<info>A training session</info> with this book takes "
3001 "<num> <info>minutes</info>.", book.time );
3002 }
3003 info.push_back( iteminfo( "BOOK", "", fmt,
3005 }
3006
3007 if( book.chapters > 0 && parts->test( iteminfo_parts::BOOK_NUMUNREADCHAPTERS ) ) {
3008 const int unread = get_remaining_chapters( you );
3009 std::string fmt = vgettext( "This book has <num> <info>unread chapter</info>.",
3010 "This book has <num> <info>unread chapters</info>.",
3011 unread );
3012 info.push_back( iteminfo( "BOOK", "", fmt, iteminfo::no_flags, unread ) );
3013 }
3014
3015 std::vector<std::string> recipe_list;
3016 for( const islot_book::recipe_with_description_t &elem : book.recipes ) {
3017 const bool knows_it = you.knows_recipe( elem.recipe );
3018 const bool can_learn = you.get_skill_level( elem.recipe->skill_used ) >= elem.skill_level;
3019 // If the player knows it, they recognize it even if it's not clearly stated.
3020 if( elem.is_hidden() && !knows_it ) {
3021 continue;
3022 }
3023 if( knows_it ) {
3024 // In case the recipe is known, but has a different name in the book, use the
3025 // real name to avoid confusing the player.
3026 const std::string name = elem.recipe->result_name();
3027 recipe_list.push_back( "<bold>" + name + "</bold>" );
3028 } else if( !can_learn ) {
3029 recipe_list.push_back( "<color_brown>" + elem.name + "</color>" );
3030 } else {
3031 recipe_list.push_back( "<dark>" + elem.name + "</dark>" );
3032 }
3033 }
3034
3035 if( !recipe_list.empty() && parts->test( iteminfo_parts::DESCRIPTION_BOOK_RECIPES ) ) {
3036 std::string recipe_line =
3037 string_format( vgettext( "This book contains %1$d crafting recipe: %2$s",
3038 "This book contains %1$d crafting recipes: %2$s",
3039 recipe_list.size() ),
3040 recipe_list.size(), enumerate_as_string( recipe_list ) );
3041
3043 info.push_back( iteminfo( "DESCRIPTION", recipe_line ) );
3044 }
3045
3046 if( recipe_list.size() != book.recipes.size() &&
3048 info.push_back( iteminfo( "DESCRIPTION",
3049 _( "It might help you figuring out some <good>more "
3050 "recipes</good>." ) ) );
3051 }
3052}
Character & get_player_character()
Definition: character.cpp:400
SkillLevel & get_skill_level_object(const skill_id &ident)
Definition: character.cpp:3344
bool knows_recipe(const recipe *rec) const
int get_skill_level(const skill_id &ident) const
Definition: character.cpp:3349
int level() const
Definition: skill.h:125
bool can_train() const
Definition: skill.cpp:311
std::string name() const
Definition: skill.h:68
bool has_identified(const itype_id &item_id) const
Note that we've read a book at least once.
Definition: avatar.cpp:953
bool is_book() const
Definition: item.cpp:6734
int get_remaining_chapters(const Character &ch) const
Get the number of unread chapters.
Definition: item.cpp:7122
translation name
Definition: martialarts.h:270
skill_id primary_skill
Definition: martialarts.h:274
std::string result_name() const
Definition: recipe.cpp:615
skill_id skill_used
Definition: recipe.h:109
@ BOOK_REQUIREMENTS_BEGINNER
@ DESCRIPTION_BOOK_ADDITIONAL_RECIPES
std::string martialart_difficulty(const matype_id &mstyle)
matype_id martial_art_learned_from(const itype &type)
Definition: martialarts.cpp:90
int get_book_fun_for(const Character &ch, const item &book)
Returns enjoyability value of a book for given character.
What recipes can be learned from this book.
Definition: itype.h:359
std::string name
The name for the recipe as it appears in the book.
Definition: itype.h:371
int skill_level
The skill level required to learn the recipe.
Definition: itype.h:367
const class recipe * recipe
The recipe that can be learned (never null).
Definition: itype.h:363
int level
The skill level the book provides.
Definition: itype.h:334
int intel
Intelligence required to read it.
Definition: itype.h:346
skill_id skill
Which skill it upgrades, if any.
Definition: itype.h:326
int req
The skill level required to understand it.
Definition: itype.h:338
recipe_list_t recipes
Definition: itype.h:384
int time
How long in minutes it takes to read.
Definition: itype.h:351
int chapters
Fun books have chapters; after all are read, the book is less fun.
Definition: itype.h:355
@ show_plus
Use a + sign for positive values.
Definition: item.h:149
cata::value_ptr< islot_book > book
Definition: itype.h:822
std::map< std::string, use_function > use_methods
Actions an instance can perform (if any) indexed by action type.
Definition: itype.h:893

References _, itype::book, BOOK_MORALECHANGE, BOOK_NUMUNREADCHAPTERS, BOOK_REQUIREMENTS_BEGINNER, BOOK_REQUIREMENTS_INT, BOOK_SKILLRANGE_MAX, BOOK_SKILLRANGE_MIN, BOOK_SUMMARY, BOOK_TIMEPERCHAPTER, BOOK_UNREAD, SkillLevel::can_train(), itype::can_use(), islot_book::chapters, DESCRIPTION_BOOK_ADDITIONAL_RECIPES, DESCRIPTION_BOOK_RECIPES, enumerate_as_string(), get_avatar(), character_funcs::get_book_fun_for(), get_player_character(), get_remaining_chapters(), Character::get_skill_level(), Character::get_skill_level_object(), avatar::has_identified(), info(), insert_separation_line(), islot_book::intel, is_book(), islot_book::recipe_with_description_t::is_hidden(), Character::knows_recipe(), islot_book::level, SkillLevel::level(), iteminfo::lower_is_better, martial_art_learned_from(), martialart_difficulty(), islot_book::recipe_with_description_t::name, martialart::name, Skill::name(), om_direction::name(), iteminfo::no_flags, string_id< T >::obj(), martialart::primary_skill, islot_book::recipe_with_description_t::recipe, islot_book::recipes, islot_book::req, recipe::result_name(), iteminfo::show_plus, islot_book::skill, islot_book::recipe_with_description_t::skill_level, recipe::skill_used, string_format(), iteminfo_query::test(), islot_book::time, type, typeId(), itype::use_methods, and vgettext().

Referenced by info().

◆ brewing_results()

const std::vector< itype_id > & item::brewing_results ( ) const

The results of fermenting this item.

Definition at line 5976 of file item.cpp.

5977{
5978 static const std::vector<itype_id> nulresult{};
5979 return is_brewable() ? type->brewable->results : nulresult;
5980}
bool is_brewable() const
Definition: item.cpp:6628
cata::value_ptr< islot_brewable > brewable
Definition: itype.h:819

References itype::brewable, is_brewable(), and type.

Referenced by final_info(), and iexamine::fvat_full().

◆ brewing_time()

time_duration item::brewing_time ( ) const

Time for this item to be fully fermented.

Definition at line 5971 of file item.cpp.

5972{
5973 return is_brewable() ? type->brewable->time : 0_turns;
5974}

References itype::brewable, is_brewable(), and type.

Referenced by final_info(), and iexamine::fvat_full().

◆ bullet_resist()

int item::bullet_resist ( bool  to_self = false) const

Definition at line 6123 of file item.cpp.

6124{
6125 if( is_null() ) {
6126 return 0;
6127 }
6128
6129 const int base_thickness = get_thickness();
6130 float resist = 0;
6132 int eff_thickness = 1;
6133
6134 // base resistance
6135 // Don't give reinforced items +armor, just more resistance to ripping
6136 const int dmg = damage_level( 4 );
6137 const int eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 );
6138 eff_thickness = std::max( 1, base_thickness - eff_damage );
6139
6140 const std::vector<const material_type *> mat_types = made_of_types();
6141 if( !mat_types.empty() ) {
6142 for( const material_type *mat : mat_types ) {
6143 resist += mat->bullet_resist();
6144 }
6145 // Average based on number of materials.
6146 resist /= mat_types.size();
6147 }
6148
6149 return std::lround( ( resist * eff_thickness ) + mod );
6150}
@ clothing_mod_type_bullet
Definition: clothing_mod.h:21

References clothing_mod_type_bullet, damage_level(), get_clothing_mod_val(), get_thickness(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), and sew_advanced_actor::use().

◆ burn()

bool item::burn ( fire_data frd)

Burns the item.

Returns true if the item was destroyed.

Definition at line 8300 of file item.cpp.

8301{
8302 float burn_added = simulate_burn( frd );
8303
8304 if( burn_added <= 0 ) {
8305 return false;
8306 }
8307
8308 if( count_by_charges() ) {
8309 if( type->volume == 0_ml ) {
8310 charges = 0;
8311 } else {
8313 ( 3.0 * type->volume ) );
8314 }
8315
8316 return charges <= 0;
8317 }
8318
8319 if( is_corpse() ) {
8320 const mtype *mt = get_mtype();
8321 if( active && mt != nullptr && burnt + burn_added > mt->hp &&
8322 !mt->burn_into.is_null() && mt->burn_into.is_valid() ) {
8323 corpse = &get_mtype()->burn_into.obj();
8324 // Delay rezing
8325 set_age( 0_turns );
8326 burnt = 0;
8327 return false;
8328 }
8329 }
8330
8331 burnt += roll_remainder( burn_added );
8332
8333 const int vol = base_volume() / units::legacy_volume_factor;
8334 return burnt >= vol * 3;
8335}
units::volume base_volume() const
Simplified, faster volume check for when processing time is important and exact volume is not.
Definition: item.cpp:5101
float simulate_burn(fire_data &frd) const
Calculate all burning calculations, but don't actually apply them to item.
Definition: item.cpp:8247
const mtype * get_mtype() const
Definition: item.cpp:6650
void set_age(const time_duration &age)
Definition: item.cpp:10039
bool is_valid() const
Returns whether this id is valid, that means whether it refers to an existing object.
Definition: achievement.cpp:67
static constexpr volume legacy_volume_factor
Definition: units_volume.h:50
int roll_remainder(double value)
Definition: rng.cpp:96
Definition: mtype.h:208
mtype_id burn_into
Definition: mtype.h:331
int hp
Definition: mtype.h:270

References active, base_volume(), mtype::burn_into, burnt, charges, corpse, count_by_charges(), get_mtype(), mtype::hp, is_corpse(), string_id< T >::is_null(), string_id< T >::is_valid(), units::legacy_volume_factor, string_id< T >::obj(), roll_remainder(), set_age(), simulate_burn(), itype::stack_size, type, and itype::volume.

Referenced by Character::absorb_hit().

◆ calc_rot()

time_duration item::calc_rot ( time_point  time,
int  temp 
) const

Returns rot of the item since last rot calculation.

This function should not be called directly. since it does not have all the needed checks or temperature calculations. If you need to calc rot of item call process_rot instead.

Parameters
timeTime point to which rot is calculated
tempTemperature at which the rot is calculated

Definition at line 5676 of file item.cpp.

5677{
5678 // Avoid needlessly calculating already rotten things. Corpses should
5679 // always rot away and food rots away at twice the shelf life. If the food
5680 // is in a sealed container they won't rot away, this avoids needlessly
5681 // calculating their rot in that case.
5682 if( !is_corpse() && get_relative_rot() > 2.0 ) {
5683 return time_duration::from_seconds( 0 );
5684 }
5685
5686 // rot modifier
5687 float factor = 1.0;
5688 if( is_corpse() && has_flag( flag_FIELD_DRESS ) ) {
5689 factor = 0.75;
5690 }
5691
5693 // simulation of different age of food at the start of the game and good/bad storage
5694 // conditions by applying starting variation bonus/penalty of +/- 20% of base shelf-life
5695 // positive = food was produced some time before calendar::start and/or bad storage
5696 // negative = food was stored in good conditions before calendar::start
5698 time_duration spoil_variation = get_shelf_life() * 0.2f;
5699 added_rot += rng( -spoil_variation, spoil_variation );
5700 }
5701
5702 time_duration time_delta = time - last_rot_check;
5703 added_rot += factor * time_delta / 1_hours * get_hourly_rotpoints_at_temp( temp ) * 1_turns;
5704 return added_rot;
5705}
A duration defined as a number of specific time units.
Definition: calendar.h:180
static constexpr time_duration from_seconds(const T t)
Definition: calendar.h:208
static const std::string flag_FIELD_DRESS("FIELD_DRESS")
int get_hourly_rotpoints_at_temp(const int temp)
Get the hourly rot for a given temperature from the precomputed table.
Definition: item.cpp:5660
@ time
Recharges slowly with time.

References flag_FIELD_DRESS(), time_duration::from_seconds(), get_hourly_rotpoints_at_temp(), get_relative_rot(), get_shelf_life(), has_flag(), is_corpse(), last_rot_check, rng(), calendar::start_of_cataclysm, and time.

Referenced by process_rot().

◆ can_contain() [1/2]

bool item::can_contain ( const item it) const

Can this item have given item/itype as content?

For example, airtight for gas, acidproof for acid etc.

Definition at line 7055 of file item.cpp.

7056{
7057 // TODO: Volume check
7058 return can_contain( *it.type );
7059}
bool can_contain(const item &it) const
Can this item have given item/itype as content?
Definition: item.cpp:7055

References can_contain(), and type.

Referenced by can_contain().

◆ can_contain() [2/2]

bool item::can_contain ( const itype tp) const

Definition at line 7061 of file item.cpp.

7062{
7063 if( !type->container ) {
7064 // TODO: Tools etc.
7065 return false;
7066 }
7067
7068 if( tp.phase == LIQUID && !type->container->watertight ) {
7069 return false;
7070 }
7071
7072 // TODO: Acid in waterskins
7073 return true;
7074}
@ LIQUID
Definition: enums.h:175
phase_id phase
Definition: itype.h:910

References itype::container, LIQUID, itype::phase, and type.

◆ can_holster()

bool item::can_holster ( const item obj,
bool  ignore = false 
) const

Checks if item is a holster and currently capable of storing obj.

Parameters
objobject that we want to holster
ignoreonly check item is compatible and ignore any existing contents

Definition at line 8893 of file item.cpp.

8894{
8895 if( !type->can_use( "holster" ) ) {
8896 return false; // item is not a holster
8897 }
8898
8899 const holster_actor *ptr = dynamic_cast<const holster_actor *>
8900 ( type->get_use( "holster" )->get_actor_ptr() );
8901 if( !ptr->can_holster( obj ) ) {
8902 return false; // item is not a suitable holster for obj
8903 }
8904
8905 if( !ignore && static_cast<int>( contents.num_item_stacks() ) >= ptr->multi ) {
8906 return false; // item is already full
8907 }
8908
8909 return true;
8910}
Holster a weapon.
Definition: iuse_actor.h:842
size_t num_item_stacks() const
returns the number of items stacks in contents each item that is not count_by_charges,...
const void * ptr(const T *p)
\rst Converts p to const void* for pointer formatting.

References itype::can_use(), contents, use_function::get_actor_ptr(), itype::get_use(), item_contents::num_item_stacks(), ptr(), and type.

◆ can_reload_with() [1/2]

bool item::can_reload_with ( const ammotype ammo) const

Returns true if this item can be reloaded with specified ammo type, ignoring currently loaded ammo.

Definition at line 6886 of file item.cpp.

6887{
6888 return is_reloadable_helper( ammo->default_ammotype(), false );
6889}
bool is_reloadable_helper(const itype_id &ammo, bool now) const
Helper for checking reloadability.
Definition: item.cpp:6901

References ammunition_type::default_ammotype(), and is_reloadable_helper().

Referenced by favorite_ammo_or_select(), avatar_funcs::gunmod_add(), and aim_activity_actor::load_RAS_weapon().

◆ can_reload_with() [2/2]

bool item::can_reload_with ( const itype_id ammo) const

Returns true if this item can be reloaded with specified ammo item, ignoring currently loaded ammo.

Definition at line 6891 of file item.cpp.

6892{
6893 return is_reloadable_helper( ammo, false );
6894}

References is_reloadable_helper().

◆ can_revive()

bool item::can_revive ( ) const

Whether this is a corpse that can be revived.

Definition at line 5982 of file item.cpp.

5983{
5984 return is_corpse() && corpse->has_flag( MF_REVIVES ) && damage() < max_damage() &&
5988}
int max_damage() const
Maximum amount of damage to an item (state before destroyed)
Definition: item.cpp:6241
static const std::string flag_QUARTERED("QUARTERED")
static const std::string flag_SKINNED("SKINNED")
static const std::string flag_FIELD_DRESS_FAILED("FIELD_DRESS_FAILED")
static const std::string flag_PULPED("PULPED")
@ MF_REVIVES
Definition: mtype.h:125
bool has_flag(m_flag flag) const
Definition: mtype.cpp:75

References corpse, damage(), flag_FIELD_DRESS(), flag_FIELD_DRESS_FAILED(), flag_PULPED(), flag_QUARTERED(), flag_SKINNED(), has_flag(), mtype::has_flag(), is_corpse(), max_damage(), and MF_REVIVES.

Referenced by active_item_cache::add(), color_in_inventory(), has_rotten_away(), ready_to_revive(), active_item_cache::remove(), basecamp::start_relay_hide_site(), and basecamp::start_setup_hide_site().

◆ can_unload_liquid()

bool item::can_unload_liquid ( ) const

Returns true if not empty if it's liquid, it's not currently frozen in resealable container.

Definition at line 6875 of file item.cpp.

6876{
6877 if( is_container_empty() ) {
6878 return true;
6879 }
6880
6881 const item &cts = contents.front();
6882 bool cts_is_frozen_liquid = cts.made_of( LIQUID ) && cts.made_of( SOLID );
6883 return is_bucket() || !cts_is_frozen_liquid;
6884}
const std::vector< material_id > & made_of() const
The ids of all the materials this is made of.
Definition: item.cpp:6438
bool is_container_empty() const
Whether this item has no contents at all.
Definition: item.cpp:6862
bool is_bucket() const
Definition: item.cpp:6759
@ SOLID
Definition: enums.h:175

References contents, item_contents::front(), is_bucket(), is_container_empty(), LIQUID, made_of(), and SOLID.

Referenced by item_funcs::can_be_unloaded(), iexamine::keg(), and avatar_funcs::unload_item().

◆ casings_count()

int item::casings_count ( ) const

How many spent casings are contained within this item?

Definition at line 8106 of file item.cpp.

8107{
8108 int res = 0;
8109
8110 const_cast<item *>( this )->casings_handle( [&res]( item & ) {
8111 ++res;
8112 return false;
8113 } );
8114
8115 return res;
8116}
void casings_handle(const std::function< bool(item &)> &func)
Apply predicate to each contained spent casing removing it if predicate returns true.
Definition: item.cpp:8118

References casings_handle().

Referenced by item_funcs::can_be_unloaded(), and avatar_funcs::unload_item().

◆ casings_handle()

void item::casings_handle ( const std::function< bool(item &)> &  func)

Apply predicate to each contained spent casing removing it if predicate returns true.

Definition at line 8118 of file item.cpp.

8119{
8120 if( !is_gun() ) {
8121 return;
8122 }
8123
8124 contents.casings_handle( func );
8125}
void casings_handle(const std::function< bool(item &)> &func)

References item_contents::casings_handle(), contents, and is_gun().

Referenced by casings_count(), avatar_funcs::gunmod_remove(), reload(), and avatar_funcs::unload_item().

◆ charges_per_volume()

int item::charges_per_volume ( const units::volume vol) const

Number of (charges of) this item that fit into the given volume.

May return 0 if not even one charge fits into the volume. Only depends on the type of this item not on its current charge count.

For items not counted by charges, this returns vol / this->volume().

Definition at line 867 of file item.cpp.

868{
869 if( count_by_charges() ) {
870 if( type->volume == 0_ml ) {
871 debugmsg( "Item '%s' with zero volume", tname() );
872 return INFINITE_CHARGES;
873 }
874 // Type cast to prevent integer overflow with large volume containers like the cargo
875 // dimension
876 return vol * static_cast<int64_t>( type->stack_size ) / type->volume;
877 } else {
878 units::volume my_volume = volume();
879 if( my_volume == 0_ml ) {
880 debugmsg( "Item '%s' with zero volume", tname() );
881 return INFINITE_CHARGES;
882 }
883 return vol / my_volume;
884 }
885}
static const int INFINITE_CHARGES
Definition: item.h:2158

References count_by_charges(), debugmsg, INFINITE_CHARGES, itype::stack_size, tname(), type, volume(), and itype::volume.

Referenced by item_stack::amount_can_fit(), Character::can_feed_furnace_with(), vehicle_part::consume_energy(), display_name(), Character::feed_furnace_with(), activity_handlers::fill_liquid_do_turn(), Character::get_acquirable_energy(), get_remaining_capacity_for_liquid(), in_container(), Item_factory::migrate_item(), Item_modifier::modify(), vehicle::print_fuel_indicator(), advanced_inventory::query_charges(), and try_fuel_fire().

◆ chip_resistance()

int item::chip_resistance ( bool  worst = false) const

Returns resistance to being damaged by attack against the item itself.

Calculated from item's materials.

Parameters
worstIf this is true, the worst resistance is used. Otherwise the best one.

Definition at line 6217 of file item.cpp.

6218{
6219 int res = worst ? INT_MAX : INT_MIN;
6220 for( const material_type *mat : made_of_types() ) {
6221 const int val = mat->chip_resist();
6222 res = worst ? std::min( res, val ) : std::max( res, val );
6223 }
6224
6225 if( res == INT_MAX || res == INT_MIN ) {
6226 return 2;
6227 }
6228
6229 if( res <= 0 ) {
6230 return 0;
6231 }
6232
6233 return res;
6234}

References made_of_types().

Referenced by Character::handle_melee_wear().

◆ clear_vars()

void item::clear_vars ( )

Removes all item variables.

Definition at line 1088 of file item.cpp.

1089{
1090 item_vars.clear();
1091}

References item_vars.

Referenced by iuse::camera(), einkpc_download_memory_card(), and iuse::einktabletpc().

◆ color()

nc_color item::color ( ) const

Returns the default color of the item (e.g.

itype::color).

Definition at line 4935 of file item.cpp.

4936{
4937 if( is_null() ) {
4938 return c_black;
4939 }
4940 if( is_corpse() ) {
4941 return corpse->color;
4942 }
4943 return type->color;
4944}
#define c_black
Definition: color.h:17
nc_color color
Definition: itype.h:974
nc_color color
Definition: mtype.h:261

References c_black, itype::color, mtype::color, corpse, is_corpse(), is_null(), and type.

Referenced by map::draw_maptile(), Character::pour_into(), and debug_menu::wishitem().

◆ color_in_inventory() [1/2]

nc_color item::color_in_inventory ( ) const

Returns the color of the item depending on usefulness for the player character, e.g.

differently if it its an unread book or a spoiling food item etc. This should only be used for displaying data, it should not affect game play.

Definition at line 4147 of file item.cpp.

4148{
4150}
nc_color color_in_inventory() const
Returns the color of the item depending on usefulness for the player character, e....
Definition: item.cpp:4147

References color_in_inventory(), and get_avatar().

Referenced by color_in_inventory(), colorized_item_name(), inventory_selector_preset::get_color(), read_inventory_preset::get_color(), avatar_funcs::gunmod_add(), game::list_items(), iuse::marloss_seed(), pickup::pick_up(), iuse::seed(), Character::takeoff(), and Character::will_eat().

◆ color_in_inventory() [2/2]

nc_color item::color_in_inventory ( const player p) const

Returns the color of the item depending on usefulness for the passed player, e.g.

differently if it its an unread book or a spoiling food item etc. This should only be used for displaying data, it should not affect game play.

Parameters
for_playerNPC or avatar which would read book.

Definition at line 4152 of file item.cpp.

4153{
4154 // Only item not otherwise colored gets colored as favorite
4156 if( type->can_use( "learn_spell" ) ) {
4157 const use_function *iuse = get_use( "learn_spell" );
4158 const learn_spell_actor *actor_ptr =
4159 static_cast<const learn_spell_actor *>( iuse->get_actor_ptr() );
4160 for( const std::string &spell_id_str : actor_ptr->spells ) {
4161 const spell_id sp_id( spell_id_str );
4162 if( p.magic->knows_spell( sp_id ) && !p.magic->get_spell( sp_id ).is_max_level() ) {
4163 ret = c_yellow;
4164 }
4165 if( !p.magic->knows_spell( sp_id ) && p.magic->can_learn_spell( p, sp_id ) ) {
4166 return c_light_blue;
4167 }
4168 }
4169 } else if( has_flag( flag_WET ) ) {
4170 ret = c_cyan;
4171 } else if( has_flag( flag_LITCIG ) ) {
4172 ret = c_red;
4173 } else if( is_armor() && p.has_trait( trait_WOOLALLERGY ) &&
4174 ( made_of( material_id( "wool" ) ) || has_own_flag( "wooled" ) ) ) {
4175 ret = c_red;
4176 } else if( is_filthy() || has_own_flag( "DIRTY" ) ) {
4177 ret = c_brown;
4178 } else if( is_bionic() ) {
4179 if( !p.has_bionic( type->bionic->id ) ) {
4180 ret = p.bionic_installation_issues( type->bionic->id ).empty() ? c_green : c_red;
4181 } else if( !has_fault( fault_bionic_nonsterile ) ) {
4182 ret = c_dark_gray;
4183 }
4184 } else if( has_flag( flag_LEAK_DAM ) && has_flag( flag_RADIOACTIVE ) && damage() > 0 ) {
4186 } else if( active && !is_food() && !is_food_container() && !is_corpse() ) {
4187 // Active items show up as yellow
4188 ret = c_yellow;
4189 } else if( is_corpse() && can_revive() ) {
4190 // Only reviving corpses are yellow
4191 ret = c_yellow;
4192 } else if( const item *food = get_food() ) {
4193 const bool preserves = type->container && type->container->preserves;
4194
4195 // Give color priority to allergy (allergy > inedible by freeze or other conditions)
4196 // TODO: refactor u.will_eat to let this section handle coloring priority without duplicating code.
4197 if( p.allergy_type( *food ) != morale_type( "morale_null" ) ) {
4198 return c_red;
4199 }
4200
4201 // Default: permafood, drugs
4202 // Brown: rotten (for non-saprophages) or non-rotten (for saprophages)
4203 // Dark gray: inedible
4204 // Red: morale penalty
4205 // Yellow: will rot soon
4206 // Cyan: will rot eventually
4207 const ret_val<edible_rating> rating = p.will_eat( *food );
4208 // TODO: More colors
4209 switch( rating.value() ) {
4212 if( preserves ) {
4213 // Nothing, canned food won't rot
4214 } else if( food->is_going_bad() ) {
4215 ret = c_yellow;
4216 } else if( food->goes_bad() ) {
4217 ret = c_cyan;
4218 }
4219 break;
4222 ret = c_dark_gray;
4223 break;
4227 ret = c_red;
4228 break;
4230 ret = c_brown;
4231 break;
4234 ret = c_pink;
4235 break;
4237 break;
4238 }
4239 } else if( is_gun() ) {
4240 // Guns are green if you are carrying ammo for them
4241 // ltred if you have ammo but no mags
4242 // Gun with integrated mag counts as both
4243 for( const ammotype &at : ammo_types() ) {
4244 // get_ammo finds uncontained ammo, find_ammo finds ammo in magazines
4245 bool has_ammo = !character_funcs::get_ammo_items( p, at ).empty() ||
4246 !character_funcs::find_ammo_items_or_mags( p, *this, false, -1 ).empty();
4247 bool has_mag = magazine_integral() ||
4248 !character_funcs::find_ammo_items_or_mags( p, *this, true, -1 ).empty();
4249 if( has_ammo && has_mag ) {
4250 ret = c_green;
4251 break;
4252 } else if( has_ammo || has_mag ) {
4253 ret = c_light_red;
4254 break;
4255 }
4256 }
4257 } else if( is_ammo() ) {
4258 // Likewise, ammo is green if you have guns that use it
4259 // ltred if you have the gun but no mags
4260 // Gun with integrated mag counts as both
4261 bool has_gun = p.has_item_with( [this]( const item & i ) {
4262 return i.is_gun() && i.ammo_types().count( ammo_type() );
4263 } );
4264 bool has_mag = p.has_item_with( [this]( const item & i ) {
4265 return ( i.is_gun() && i.magazine_integral() && i.ammo_types().count( ammo_type() ) ) ||
4266 ( i.is_magazine() && i.ammo_types().count( ammo_type() ) );
4267 } );
4268 if( has_gun && has_mag ) {
4269 ret = c_green;
4270 } else if( has_gun || has_mag ) {
4271 ret = c_light_red;
4272 }
4273 } else if( is_magazine() ) {
4274 // Magazines are green if you have guns and ammo for them
4275 // ltred if you have one but not the other
4276 bool has_gun = p.has_item_with( [this]( const item & it ) {
4277 return it.is_gun() && it.magazine_compatible().count( typeId() ) > 0;
4278 } );
4279 bool has_ammo = !character_funcs::find_ammo_items_or_mags( p, *this, false, -1 ).empty();
4280 if( has_gun && has_ammo ) {
4281 ret = c_green;
4282 } else if( has_gun || has_ammo ) {
4283 ret = c_light_red;
4284 }
4285 } else if( is_book() ) {
4286 const islot_book &tmp = *type->book;
4287 // Player doesn't actually interested if NPC has identified book yet.
4288 // So we check identification for human avatar.
4289 if( get_avatar().has_identified( typeId() ) ) {
4290 if( tmp.skill && // Book can improve skill: blue
4292 p.get_skill_level( tmp.skill ) >= tmp.req &&
4293 p.get_skill_level( tmp.skill ) < tmp.level ) {
4294 ret = c_light_blue;
4295 } else if( type->can_use( "MA_MANUAL" ) &&
4296 !p.martial_arts_data->has_martialart( martial_art_learned_from( *type ) ) ) {
4297 ret = c_light_blue;
4298 } else if( tmp.skill && // Book can't improve skill right now, but maybe later: pink
4300 p.get_skill_level( tmp.skill ) < tmp.level ) {
4301 ret = c_pink;
4302 } else if( !p.studied_all_recipes(
4303 *type ) ) { // Book can't improve skill anymore, but has more recipes: yellow
4304 ret = c_yellow;
4305 }
4306 } else if( tmp.skill || type->can_use( "MA_MANUAL" ) ) {
4307 // Book can teach you something and hasn't been identified yet
4308 ret = c_red;
4309 } else {
4310 // "just for fun" book that they haven't read yet
4311 ret = c_magenta;
4312 }
4313 }
4314 return ret;
4315}
morale_type allergy_type(const item &food) const
Returns allergy type or MORALE_NULL if not allergic for this character.
pimpl< character_martial_arts > martial_arts_data
Definition: character.h:1588
ret_val< edible_rating > will_eat(const item &food, bool interactive=false) const
Same as can_eat, but takes consequences into account.
bool has_bionic(const bionic_id &b) const
Returns true if the player has the entered bionic id.
Definition: character.cpp:1812
std::map< bodypart_id, int > bionic_installation_issues(const bionic_id &bioid) const
Definition: bionics.cpp:2574
bool has_trait(const trait_id &b) const override
Returns true if the player has the entered trait.
Definition: mutation.cpp:101
pimpl< known_magic > magic
Definition: character.h:1485
bool is_favorite
Definition: item.h:2239
std::set< itype_id > magazine_compatible(bool conversion=true) const
Get compatible magazines (if any) for this item.
Definition: item.cpp:7713
bool has_fault(const fault_id &fault) const
Does this item have the specified fault.
Definition: item.cpp:5318
bool is_filthy() const
Marks the item as filthy, so characters with squeamish trait can't wear it.
Definition: item.cpp:10010
bool is_food_container() const
Definition: item.cpp:6633
const use_function * get_use(const std::string &use_name) const
Returns the pointer to use_function with name use_name assigned to the type of this item or any of it...
Definition: item.cpp:7964
bool can_revive() const
Whether this is a corpse that can be revived.
Definition: item.cpp:5982
bool has_own_flag(const std::string &flag) const
Checks whether item itself has given flag (doesn't check item type or gunmods).
Definition: item.cpp:5323
Learn a spell.
Definition: iuse_actor.h:799
std::vector< std::string > spells
Definition: iuse_actor.h:802
bool studied_all_recipes(const itype &book) const
Definition: player.cpp:264
The class represents a composite return value of an arbitrary function (result).
Definition: ret_val.h:21
T value() const
Definition: ret_val.h:74
bool has_item_with(const std::function< bool(const item &)> &filter) const
Returns true if any item (including those within a container) matches the filter.
Definition: visitable.cpp:104
#define c_white
Definition: color.h:18
#define c_light_gray
Definition: color.h:19
#define c_green
Definition: color.h:22
#define c_light_green
Definition: color.h:28
#define c_magenta
Definition: color.h:25
#define c_brown
Definition: color.h:26
#define c_dark_gray
Definition: color.h:20
#define c_pink
Definition: color.h:31
#define c_yellow
Definition: color.h:32
#define c_cyan
Definition: color.h:24
#define c_light_red
Definition: color.h:27
#define c_red
Definition: color.h:21
static const std::string flag_WET("WET")
static const trait_id trait_WOOLALLERGY("WOOLALLERGY")
static const fault_id fault_bionic_nonsterile("fault_bionic_nonsterile")
static const std::string flag_LEAK_DAM("LEAK_DAM")
static const std::string flag_LITCIG("LITCIG")
static const std::string flag_RADIOACTIVE("RADIOACTIVE")
std::vector< const item * > get_ammo_items(const Character &who, const ammotype &at)
Returns character's items that are ammo and have the matching ammo type.
std::vector< item_location > find_ammo_items_or_mags(const Character &who, const item &obj, bool empty, int radius)
Searches for ammo or magazines that can be used to reload given item.
Definition: iuse.h:25
string_id< material_type > material_id
Definition: type_id.h:95

References active, allergy, Character::allergy_type(), allergy_weak, ammo_type(), ammo_types(), itype::bionic, Character::bionic_installation_issues(), bloated, itype::book, c_brown, c_cyan, c_dark_gray, c_green, c_light_blue, c_light_gray, c_light_green, c_light_red, c_magenta, c_pink, c_red, c_white, c_yellow, can_revive(), SkillLevel::can_train(), itype::can_use(), cannibalism, itype::container, damage(), edible, fault_bionic_nonsterile, character_funcs::find_ammo_items_or_mags(), flag_LEAK_DAM(), flag_LITCIG(), flag_RADIOACTIVE(), flag_WET(), character_funcs::get_ammo_items(), get_avatar(), get_food(), Character::get_skill_level(), Character::get_skill_level_object(), get_use(), Character::has_bionic(), has_fault(), has_flag(), visitable< T >::has_item_with(), has_own_flag(), Character::has_trait(), inedible, inedible_mutation, is_ammo(), is_armor(), is_bionic(), is_book(), is_corpse(), is_favorite, is_filthy(), is_food(), is_food_container(), is_gun(), is_magazine(), islot_book::level, made_of(), magazine_compatible(), magazine_integral(), Character::magic, martial_art_learned_from(), Character::martial_arts_data, nausea, no_tool, islot_book::req, cata::hash64_detail::ret, rotten, islot_book::skill, learn_spell_actor::spells, player::studied_all_recipes(), too_full, trait_WOOLALLERGY, type, typeId(), ret_val< T >::value(), and Character::will_eat().

◆ combat_info()

void item::combat_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3418 of file item.cpp.

3420{
3421 const std::string space = " ";
3422
3423 int dmg_bash = damage_melee( DT_BASH );
3424 int dmg_cut = damage_melee( DT_CUT );
3425 int dmg_stab = damage_melee( DT_STAB );
3426 if( parts->test( iteminfo_parts::BASE_DAMAGE ) ) {
3428 std::string sep;
3429 if( dmg_bash || dmg_cut || dmg_stab ) {
3430 info.push_back( iteminfo( "BASE", _( "<bold>Melee damage</bold>: " ), "", iteminfo::no_newline ) );
3431 }
3432 if( dmg_bash ) {
3433 info.push_back( iteminfo( "BASE", _( "Bash: " ), "", iteminfo::no_newline, dmg_bash ) );
3434 sep = space;
3435 }
3436 if( dmg_cut ) {
3437 info.push_back( iteminfo( "BASE", sep + _( "Cut: " ), "", iteminfo::no_newline, dmg_cut ) );
3438 sep = space;
3439 }
3440 if( dmg_stab ) {
3441 info.push_back( iteminfo( "BASE", sep + _( "Pierce: " ), "", iteminfo::no_newline, dmg_stab ) );
3442 }
3443 }
3444
3445 if( dmg_bash || dmg_cut || dmg_stab ) {
3446 if( parts->test( iteminfo_parts::BASE_TOHIT ) ) {
3447 info.push_back( iteminfo( "BASE", space + _( "To-hit bonus: " ), "",
3449 }
3450
3451 if( parts->test( iteminfo_parts::BASE_MOVES ) ) {
3452 info.push_back( iteminfo( "BASE", _( "Moves per attack: " ), "",
3454 info.emplace_back( "BASE", _( "Typical damage per second:" ), "" );
3455 const std::map<std::string, double> &dps_data = dps( true, false );
3456 std::string sep;
3457 for( const std::pair<const std::string, double> &dps_entry : dps_data ) {
3458 info.emplace_back( "BASE", sep + dps_entry.first + ": ", "",
3460 dps_entry.second );
3461 sep = space;
3462 }
3463 info.emplace_back( "BASE", "" );
3464 }
3465 }
3466
3468 std::set<matec_id> all_techniques = type->techniques;
3469 all_techniques.insert( techniques.begin(), techniques.end() );
3470
3471 if( !all_techniques.empty() ) {
3472 const std::vector<matec_id> all_tec_sorted = sorted_lex( all_techniques );
3474 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Techniques when wielded</bold>: " ) +
3475 enumerate_as_string( all_tec_sorted.begin(), all_tec_sorted.end(), []( const matec_id & tid ) {
3476 return string_format( "<stat>%s</stat>: <info>%s</info>", _( tid.obj().name ),
3477 _( tid.obj().description ) );
3478 } ) ) );
3479 }
3480 }
3481
3482 avatar &you = get_avatar();
3483 // display which martial arts styles character can use with this weapon
3485 const std::string valid_styles = you.martial_arts_data->enumerate_known_styles( typeId() );
3486 if( !valid_styles.empty() ) {
3488 info.push_back( iteminfo( "DESCRIPTION",
3489 _( "You know how to use this with these martial arts "
3490 "styles: " ) + valid_styles ) );
3491 }
3492 }
3493
3494 if( !is_gunmod() && has_flag( flag_REACH_ATTACK ) &&
3497 if( has_flag( flag_REACH3 ) ) {
3498 info.push_back( iteminfo( "DESCRIPTION",
3499 _( "* This item can be used to make <stat>long reach "
3500 "attacks</stat>." ) ) );
3501 } else {
3502 info.push_back( iteminfo( "DESCRIPTION",
3503 _( "* This item can be used to make <stat>reach "
3504 "attacks</stat>." ) ) );
3505 }
3506 }
3507
3508 if( ( dmg_bash || dmg_cut || dmg_stab || type->m_to_hit > 0 ) || debug_mode ) {
3509 damage_instance non_crit;
3510 you.roll_all_damage( false, non_crit, true, *this );
3511 damage_instance crit;
3512 you.roll_all_damage( true, crit, true, *this );
3513 int attack_cost = you.attack_cost( *this );
3516 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Average melee damage</bold>:" ) ) );
3517 }
3518 // Chance of critical hit
3520 info.push_back( iteminfo( "DESCRIPTION",
3521 string_format( _( "Critical hit chance <neutral>%d%% - %d%%</neutral>" ),
3522 static_cast<int>( you.crit_chance( 0, 100, *this ) *
3523 100 ),
3524 static_cast<int>( you.crit_chance( 100, 0, *this ) *
3525 100 ) ) ) );
3526 }
3527 // Bash damage
3529 // NOTE: Using "BASE" instead of "DESCRIPTION", so numerical formatting will work
3530 // (output.cpp:format_item_info does not interpolate <num> for DESCRIPTION info)
3531 info.push_back( iteminfo( "BASE", _( "Bashing: " ), "<num>", iteminfo::no_newline,
3532 non_crit.type_damage( DT_BASH ) ) );
3533 info.push_back( iteminfo( "BASE", space + _( "Critical bash: " ), "<num>", iteminfo::no_flags,
3534 crit.type_damage( DT_BASH ) ) );
3535 }
3536 // Cut damage
3537 if( ( non_crit.type_damage( DT_CUT ) > 0.0f || crit.type_damage( DT_CUT ) > 0.0f )
3539
3540 info.push_back( iteminfo( "BASE", _( "Cutting: " ), "<num>", iteminfo::no_newline,
3541 non_crit.type_damage( DT_CUT ) ) );
3542 info.push_back( iteminfo( "BASE", space + _( "Critical cut: " ), "<num>", iteminfo::no_flags,
3543 crit.type_damage( DT_CUT ) ) );
3544 }
3545 // Pierce/stab damage
3546 if( ( non_crit.type_damage( DT_STAB ) > 0.0f || crit.type_damage( DT_STAB ) > 0.0f )
3548
3549 info.push_back( iteminfo( "BASE", _( "Piercing: " ), "<num>", iteminfo::no_newline,
3550 non_crit.type_damage( DT_STAB ) ) );
3551 info.push_back( iteminfo( "BASE", space + _( "Critical pierce: " ), "<num>", iteminfo::no_flags,
3552 crit.type_damage( DT_STAB ) ) );
3553 }
3554 // Moves
3556 info.push_back( iteminfo( "BASE", _( "Moves per attack: " ), "<num>",
3558 }
3560 }
3561}
bool debug_mode
Extended debugging mode, can be toggled during game.
int attack_cost(const item &weap) const
Returns cost (in moves) of attacking with given item (no modifiers, like stuck)
Definition: melee.cpp:2279
double crit_chance(float roll_hit, float target_dodge, const item &weap) const
Returns the chance to critical given a hit roll and target's dodge roll.
Definition: melee.cpp:796
void roll_all_damage(bool crit, damage_instance &di, bool average, const item &weap) const
Adds all 3 types of physical damage to instance.
Definition: melee.cpp:411
int attack_cost() const
Base number of moves (Creature::moves) that a single melee attack with this items takes.
Definition: item.cpp:5206
@ DT_STAB
Definition: damage.h:27
@ DT_BASH
Definition: damage.h:24
@ DT_CUT
Definition: damage.h:25
static const std::string flag_REACH3("REACH3")
static const std::string flag_REACH_ATTACK("REACH_ATTACK")
@ DESCRIPTION_MELEEDMG_PIERCE
@ DESCRIPTION_GUNMOD_ADDREACHATTACK
@ DESCRIPTION_MELEEDMG_MOVES
@ DESCRIPTION_APPLICABLEMARTIALARTS
float type_damage(damage_type dt) const
Definition: damage.cpp:64
int m_to_hit
Definition: itype.h:966
std::set< matec_id > techniques
Definition: itype.h:901

References _, attack_cost(), Character::attack_cost(), BASE_DAMAGE, BASE_MOVES, BASE_TOHIT, Character::crit_chance(), damage_melee(), debug_mode, DESCRIPTION_APPLICABLEMARTIALARTS, DESCRIPTION_GUNMOD_ADDREACHATTACK, DESCRIPTION_MELEEDMG, DESCRIPTION_MELEEDMG_BASH, DESCRIPTION_MELEEDMG_CRIT, DESCRIPTION_MELEEDMG_CUT, DESCRIPTION_MELEEDMG_MOVES, DESCRIPTION_MELEEDMG_PIERCE, DESCRIPTION_TECHNIQUES, dps(), DT_BASH, DT_CUT, DT_STAB, enumerate_as_string(), flag_REACH3(), flag_REACH_ATTACK(), get_avatar(), has_flag(), info(), insert_separation_line(), iteminfo::is_decimal, is_gunmod(), iteminfo::lower_is_better, itype::m_to_hit, Character::martial_arts_data, iteminfo::no_flags, iteminfo::no_newline, Character::roll_all_damage(), iteminfo::show_plus, sorted_lex(), sign::space, string_format(), techniques, itype::techniques, iteminfo_query::test(), type, damage_instance::type_damage(), and typeId().

Referenced by info().

◆ common_ammo_default()

itype_id item::common_ammo_default ( bool  conversion = true) const

Get default ammo for the first ammotype common to an item and its current magazine or "NULL" if none exists.

Parameters
conversionwhether to include the effect of any flags or mods which convert the type
Returns
itype_id of default ammo for the first ammotype common to an item and its current magazine or "NULL" if none exists

Definition at line 7629 of file item.cpp.

7630{
7631 if( !ammo_types( conversion ).empty() ) {
7632 for( const ammotype &at : ammo_types( conversion ) ) {
7633 const item *mag = magazine_current();
7634 if( mag && mag->type->magazine->type.count( at ) ) {
7635 itype_id res = at->default_ammotype();
7636 if( !res.is_empty() ) {
7637 return res;
7638 }
7639 }
7640 }
7641 }
7642 return itype_id::NULL_ID();
7643}

References ammo_types(), string_id< T >::is_empty(), itype::magazine, magazine_current(), string_id< itype >::NULL_ID(), and type.

Referenced by gun_info().

◆ component_info()

void item::component_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3149 of file item.cpp.

3151{
3153 return;
3154 }
3155 if( is_craft() ) {
3156 info.push_back( iteminfo( "DESCRIPTION", string_format( _( "Using: %s" ),
3157 _( components_to_string() ) ) ) );
3158 // Ugly hack warning! Corpses have CBMs as their components
3159 } else if( !is_corpse() ) {
3160 info.push_back( iteminfo( "DESCRIPTION", string_format( _( "Made from: %s" ),
3161 _( components_to_string() ) ) ) );
3162 } else if( get_var( "bionics_scanned_by", -1 ) == get_avatar().getID().get_value() ) {
3163 // TODO: Extract into a more proper place (function in namespace)
3164 std::string bionics_string = enumerate_as_string( components.begin(), components.end(),
3165 []( const item & entry ) -> std::string {
3166 return entry.is_bionic() ? entry.display_name() : "";
3168 info.push_back( iteminfo( "DESCRIPTION", string_format( _( "Contains: %s" ),
3169 bionics_string ) ) );
3170 }
3171}
std::string components_to_string() const
List of all components in printable form, empty if this item has no components.
Definition: item.cpp:8912
@ DESCRIPTION_COMPONENTS_MADEFROM

References _, components, components_to_string(), DESCRIPTION_COMPONENTS_MADEFROM, enumerate_as_string(), get_avatar(), get_var(), info(), is_corpse(), is_craft(), none, string_format(), and iteminfo_query::test().

Referenced by info().

◆ components_to_string()

std::string item::components_to_string ( ) const

List of all components in printable form, empty if this item has no components.

Definition at line 8912 of file item.cpp.

8913{
8914 using t_count_map = std::map<std::string, int>;
8915 t_count_map counts;
8916 for( const item &elem : components ) {
8917 if( !elem.has_flag( flag_BYPRODUCT ) ) {
8918 const std::string name = elem.display_name();
8919 counts[name]++;
8920 }
8921 }
8922 return enumerate_as_string( counts.begin(), counts.end(),
8923 []( const std::pair<std::string, int> &entry ) -> std::string {
8924 if( entry.second != 1 )
8925 {
8926 return string_format( pgettext( "components count", "%d x %s" ), entry.second, entry.first );
8927 } else
8928 {
8929 return entry.first;
8930 }
8932}
static const std::string flag_BYPRODUCT("BYPRODUCT")

References components, enumerate_as_string(), flag_BYPRODUCT(), and om_direction::name().

Referenced by component_info().

◆ conductive()

bool item::conductive ( ) const

Whether the items is conductive.

Definition at line 6503 of file item.cpp.

6504{
6505 if( is_null() ) {
6506 return false;
6507 }
6508
6509 if( has_flag( flag_CONDUCTIVE ) ) {
6510 return true;
6511 }
6512
6513 if( has_flag( flag_NONCONDUCTIVE ) ) {
6514 return false;
6515 }
6516
6517 // If any material has electricity resistance equal to or lower than flesh (1) we are conductive.
6518 const std::vector<const material_type *> &mats = made_of_types();
6519 return std::any_of( mats.begin(), mats.end(), []( const material_type * mt ) {
6520 return mt->elec_resist() <= 1;
6521 } );
6522}
static const std::string flag_CONDUCTIVE("CONDUCTIVE")
static const std::string flag_NONCONDUCTIVE("NONCONDUCTIVE")

References flag_CONDUCTIVE(), flag_NONCONDUCTIVE(), has_flag(), is_null(), and made_of_types().

Referenced by Character::block_hit(), final_info(), and mdefense::zapback().

◆ contain_monster()

int item::contain_monster ( const tripoint target)

Definition at line 9259 of file iuse.cpp.

9260{
9261 const monster *const mon_ptr = g->critter_at<monster>( target );
9262 if( !mon_ptr ) {
9263 return 0;
9264 }
9265 const monster &f = *mon_ptr;
9266
9267 set_var( "contained_json", ::serialize( f ) );
9268 set_var( "contained_name", f.type->nname() );
9269 set_var( "name", string_format( _( "%s holding %s" ), type->nname( 1 ),
9270 f.type->nname() ) );
9271 // Need to add the weight of the empty container because item::weight uses the "weight" variable directly.
9272 set_var( "weight", to_milligram( type->weight + f.get_weight() ) );
9273 g->remove_zombie( f );
9274 return 0;
9275}
void serialize(JsonOut &json) const
const mtype * type
Definition: monster.h:478
units::mass get_weight() const override
Definition: monster.cpp:2734
constexpr value_type to_milligram(const quantity< value_type, mass_in_milligram_tag > &v)
Definition: units_mass.h:62
units::mass weight
Weight of item ( or each stack member )
Definition: itype.h:933
std::string nname(unsigned int quantity) const
Definition: itype.cpp:78
std::string nname(unsigned int quantity=1) const
Definition: mtype.cpp:65

References _, g, monster::get_weight(), itype::nname(), mtype::nname(), serialize(), set_var(), string_format(), units::to_milligram(), type, monster::type, and itype::weight.

Referenced by iuse::capture_monster_act().

◆ container_info()

void item::container_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3054 of file item.cpp.

3056{
3057 if( !is_container() || !parts->test( iteminfo_parts::CONTAINER_DETAILS ) ) {
3058 return;
3059 }
3060
3062 const islot_container &c = *type->container;
3063
3064 std::string container_str = _( "This container " );
3065
3066 if( c.seals ) {
3067 container_str += _( "can be <info>resealed</info>, " );
3068 }
3069 if( c.watertight ) {
3070 container_str += _( "is <info>watertight</info>, " );
3071 }
3072 if( c.preserves ) {
3073 container_str += _( "<good>prevents spoiling</good>, " );
3074 }
3075
3076 container_str += string_format( _( "can store <info>%s %s</info>." ),
3077 format_volume( c.contains ), volume_units_long() );
3078
3079 info.push_back( iteminfo( "CONTAINER", container_str ) );
3080}
bool is_container() const
Whether this is container.
Definition: item.cpp:6744
std::string format_volume(const units::volume &volume)
Convert, round up and format a volume.
Definition: output.cpp:2020
const char * volume_units_long()
Create a units label for a volume value.

References _, c, itype::container, CONTAINER_DETAILS, format_volume(), info(), insert_separation_line(), is_container(), string_format(), iteminfo_query::test(), type, and volume_units_long().

Referenced by info().

◆ contents_info()

void item::contents_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3563 of file item.cpp.

3565{
3567 return;
3568 }
3569 const std::string space = " ";
3570
3571 for( const item *mod : is_gun() ? gunmods() : toolmods() ) {
3572 std::string mod_str;
3573 if( mod->type->gunmod ) {
3574 if( mod->is_irremovable() ) {
3575 mod_str = _( "Integrated mod: " );
3576 } else {
3577 mod_str = _( "Mod: " );
3578 }
3579 mod_str += string_format( "<bold>%s</bold> (%s) ", mod->tname(),
3580 mod->type->gunmod->location.name() );
3581 }
3583 info.emplace_back( "DESCRIPTION", mod_str );
3584 info.emplace_back( "DESCRIPTION", mod->type->description.translated() );
3585 }
3586 bool contents_header = false;
3587 for( const item *contents_item : contents.all_items_top() ) {
3588 if( !contents_item->type->mod ) {
3589 if( !contents_header ) {
3591 info.emplace_back( "DESCRIPTION", _( "<bold>Contents of this item</bold>:" ) );
3592 contents_header = true;
3593 } else {
3594 // Separate items with a blank line
3595 info.emplace_back( "DESCRIPTION", space );
3596 }
3597
3598 const translation &description = contents_item->type->description;
3599
3600 if( contents_item->made_of( LIQUID ) ) {
3601 units::volume contents_volume = contents_item->volume() * batch;
3602 int converted_volume_scale = 0;
3603 const double converted_volume =
3604 round_up( convert_volume( contents_volume.value(),
3605 &converted_volume_scale ), 2 );
3606 info.emplace_back( "DESCRIPTION", contents_item->display_name() );
3608 if( display_mod_source ) {
3609 info.emplace_back( "DESCRIPTION", string_format( _( "<stat>Origin: %s</stat>" ),
3610 enumerate_as_string( contents_item->type->src.begin(),
3611 contents_item->type->src.end(), []( const std::pair<itype_id, mod_id> &content_source ) {
3612 return string_format( "'%s'", content_source.second->name() );
3614 }
3615 if( display_object_ids ) {
3616 info.emplace_back( "DESCRIPTION", colorize(
3617 string_format( "[%s]", contents_item->type->get_id() ),
3618 c_light_blue ) );
3619 }
3620 if( converted_volume_scale != 0 ) {
3622 }
3623 info.emplace_back( "CONTAINER", description + space,
3624 string_format( "<num> %s", volume_units_abbr() ), f,
3625 converted_volume );
3626 } else {
3627 info.emplace_back( "DESCRIPTION", contents_item->display_name() );
3628 if( display_mod_source ) {
3629 info.emplace_back( "DESCRIPTION", string_format( _( "<stat>Origin: %s</stat>" ),
3630 enumerate_as_string( contents_item->type->src.begin(),
3631 contents_item->type->src.end(), []( const std::pair<itype_id, mod_id> &content_source ) {
3632 return string_format( "'%s'", content_source.second->name() );
3634 }
3635 if( display_object_ids ) {
3636 info.emplace_back( "DESCRIPTION", colorize(
3637 string_format( "[%s]", contents_item->type->get_id() ),
3638 c_light_blue ) );
3639 }
3640 info.emplace_back( "DESCRIPTION", description.translated() );
3641 }
3642 }
3643 }
3644}
Class for storing translation context and raw string for deferred translation.
Definition: translations.h:152
constexpr const value_type & value() const
Access the raw dimensionless value.
Definition: units_def.h:44

References _, item_contents::all_items_top(), arrow, c_light_blue, colorize(), contents, convert_volume(), DESCRIPTION_CONTENTS, display_mod_source, display_object_ids, item_contents::empty(), enumerate_as_string(), gunmods(), info(), insert_separation_line(), iteminfo::is_decimal, is_gun(), LIQUID, iteminfo::no_newline, round_up(), sign::space, string_format(), iteminfo_query::test(), toolmods(), translation::translated(), units::quantity< V, U >::value(), and volume_units_abbr().

Referenced by info().

◆ contents_made_of()

bool item::contents_made_of ( phase_id  phase) const

If contents nonempty, return true if item phase is same, else false.

Definition at line 6490 of file item.cpp.

6491{
6492 return !contents.empty() && contents.front().made_of( phase );
6493}

References contents, item_contents::empty(), item_contents::front(), and made_of().

Referenced by character_funcs::find_ammo_helper().

◆ contextualize_skill()

skill_id item::contextualize_skill ( const skill_id id) const

Puts the skill in context of the item.

Definition at line 9995 of file item.cpp.

9996{
9997 if( id->is_contextual_skill() ) {
9998 if( id == skill_weapon ) {
9999 if( is_gun() ) {
10000 return gun_skill();
10001 } else if( is_melee() ) {
10002 return melee_skill();
10003 }
10004 }
10005 }
10006
10007 return id;
10008}
skill_id gun_skill() const
The skill used to operate the gun.
Definition: item.cpp:7212
skill_id melee_skill() const
The most relevant skill used with this melee weapon.
Definition: item.cpp:7220
bool is_melee() const
Is this item an effective melee weapon for any damage type?
Definition: item.cpp:6692
static const skill_id skill_weapon("weapon")
const std::string id
Definition: basecamp.h:87

References gun_skill(), base_camps::id, is_gun(), is_melee(), melee_skill(), and skill_weapon.

Referenced by Character::enumerate_unmet_requirements(), and SkillLevelMap::get_skill_level().

◆ convert()

◆ corpse_volume()

units::volume item::corpse_volume ( const mtype corpse) const

Volume check for corpses, helper for base_volume().

Definition at line 5079 of file item.cpp.

5080{
5082 if( has_flag( flag_QUARTERED ) ) {
5083 corpse_volume /= 4;
5084 }
5086 corpse_volume *= 0.75;
5087 }
5088 if( has_flag( flag_GIBBED ) ) {
5089 corpse_volume *= 0.85;
5090 }
5091 if( has_flag( flag_SKINNED ) ) {
5092 corpse_volume *= 0.85;
5093 }
5094 if( corpse_volume > 0_ml ) {
5095 return corpse_volume;
5096 }
5097 debugmsg( "invalid monster volume for corpse" );
5098 return 0_ml;
5099}
static const std::string flag_GIBBED("GIBBED")
units::volume volume
Definition: mtype.h:263

References corpse, corpse_volume(), debugmsg, flag_FIELD_DRESS(), flag_FIELD_DRESS_FAILED(), flag_GIBBED(), flag_QUARTERED(), flag_SKINNED(), has_flag(), and mtype::volume.

Referenced by base_volume(), corpse_volume(), and volume().

◆ count()

◆ count_by_charges() [1/2]

bool item::count_by_charges ( ) const

Definition at line 6030 of file item.cpp.

6031{
6032 return type->count_by_charges();
6033}

References itype::count_by_charges(), and type.

Referenced by activity_on_turn_wear(), vehicle::add_charges(), vehicle::add_item(), map::add_item_or_charges(), item_stack::amount_can_fit(), base_volume(), basic_info(), burn(), Character::can_eat(), repair_item_actor::can_repair_target(), charges_of_internal(), charges_per_volume(), craft_command::check_item_components_missing(), complete_craft(), crafting::complete_disassemble(), player::consume_items(), count(), craft_has_charges(), recipe::create_byproducts(), recipe::create_results(), display_name(), display_stacked_with(), move_items_activity_actor::do_turn(), throw_activity_actor::do_turn(), mattack::eat_food(), farm_action(), Character::feed_furnace_with(), fetch_activity(), talk_function::field_harvest(), talk_function::field_plant(), iuse_transform::finalize(), emit_actor::finalize(), for_each_item_in_both(), Character::get_acquirable_energy(), recipe::get_consistency_error(), requirement_data::get_folded_list(), iexamine::get_harvest_items(), monexamine::give_items_to(), repair_item_actor::handle_components(), item_comp::has(), talk_function::individual_mission(), io(), repair_inventory_preset::is_shown(), merge_charges(), to_cbc_migration::migration_required(), mod_charges(), mod_damage(), Item_modifier::modify(), advanced_inventory::move_all_items(), move_item(), npc_throw(), pickup::obtain_and_tokenize_items(), pick_one_up(), pickup::pick_up(), activity_handlers::plant_seed_finish(), price(), advanced_inventory::query_charges(), vehicle::reload_seeds(), player::select_item_component(), talk_effect_fun_t::set_u_buy_item(), talk_effect_fun_t::set_u_sell_item(), simulate_burn(), spell_effect::spawn_ethereal_item(), split(), stacks_with(), Character::throw_range(), ranged::throwing_dispersion(), npc_trading::trade(), try_consume(), units_remaining(), units_sufficient(), inventory::update_quality_cache(), use_charges(), volume(), weight(), Character::weight_carried_reduced_by(), and debug_menu::wishitem().

◆ count_by_charges() [2/2]

bool item::count_by_charges ( const itype_id id)
static

Whether the item is counted by charges, this is a static wrapper around count_by_charges, that does not need an items instance.

Definition at line 9956 of file item.cpp.

9957{
9958 return id->count_by_charges();
9959}

◆ covers() [1/2]

◆ covers() [2/2]

bool item::covers ( const bodypart_id bp) const

Definition at line 751 of file item.cpp.

752{
753 return get_covered_body_parts().test( bp->token );
754}
bool test(const body_part &bp) const
Definition: bodypart.h:250

References get_covered_body_parts(), and body_part_set::test().

◆ craft_has_charges()

bool item::craft_has_charges ( )

Definition at line 6040 of file item.cpp.

6041{
6042 if( count_by_charges() ) {
6043 return true;
6044 } else if( ammo_types().empty() ) {
6045 return true;
6046 }
6047
6048 return false;
6049}

References ammo_types(), and count_by_charges().

Referenced by crafting::complete_disassemble(), and recipe::create_byproducts().

◆ cut_resist()

int item::cut_resist ( bool  to_self = false) const

Definition at line 6084 of file item.cpp.

6085{
6086 if( is_null() ) {
6087 return 0;
6088 }
6089
6090 const int base_thickness = get_thickness();
6091 float resist = 0;
6093 int eff_thickness = 1;
6094
6095 // base resistance
6096 // Don't give reinforced items +armor, just more resistance to ripping
6097 const int dmg = damage_level( 4 );
6098 const int eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 );
6099 eff_thickness = std::max( 1, base_thickness - eff_damage );
6100
6101 const std::vector<const material_type *> mat_types = made_of_types();
6102 if( !mat_types.empty() ) {
6103 for( const material_type *mat : mat_types ) {
6104 resist += mat->cut_resist();
6105 }
6106 // Average based on number of materials.
6107 resist /= mat_types.size();
6108 }
6109
6110 return std::lround( ( resist * eff_thickness ) + mod );
6111}
@ clothing_mod_type_cut
Definition: clothing_mod.h:20

References clothing_mod_type_cut, damage_level(), get_clothing_mod_val(), get_thickness(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), stab_resist(), and sew_advanced_actor::use().

◆ damage()

◆ damage_color()

nc_color item::damage_color ( ) const

Provide color for UI display dependent upon current item damage level.

Definition at line 6288 of file item.cpp.

6289{
6290 // TODO: unify with veh_interact::countDurability
6291 switch( damage_level( 4 ) ) {
6292 default:
6293 // reinforced
6294 if( damage() <= min_damage() ) {
6295 // fully reinforced
6296 return c_green;
6297 } else {
6298 return c_light_green;
6299 }
6300 case 0:
6301 return c_light_green;
6302 case 1:
6303 return c_yellow;
6304 case 2:
6305 return c_magenta;
6306 case 3:
6307 return c_light_red;
6308 case 4:
6309 if( damage() >= max_damage() ) {
6310 return c_dark_gray;
6311 } else {
6312 return c_red;
6313 }
6314 }
6315}
int min_damage() const
Minimum amount of damage to an item (state of maximum repair)
Definition: item.cpp:6236

References c_dark_gray, c_green, c_light_green, c_light_red, c_magenta, c_red, c_yellow, damage(), damage_level(), max_damage(), and min_damage().

Referenced by durability_indicator(), vehicle_part::name(), and veh_utils::repair_part().

◆ damage_level()

int item::damage_level ( int  max) const

Scale item damage to the given number of levels.

This function is here mostly for back-compatibility. It should not be used when doing continuous math with the damage value: use damage() instead.

For example, for max = 4, min_damage = -1000, max_damage = 4000 damage level -1000 ~ -1 -1 0 0 1 ~ 1333 1 1334 ~ 2666 2 2667 ~ 3999 3 4000 4

Parameters
maxMaximum number of levels

Definition at line 704 of file item.cpp.

705{
706 if( damage_ == 0 || max <= 0 ) {
707 return 0;
708 } else if( max_damage() <= 1 ) {
709 return damage_ > 0 ? max : damage_;
710 } else if( damage_ < 0 ) {
711 return -( ( max - 1 ) * ( -damage_ - 1 ) / ( max_damage() - 1 ) + 1 );
712 } else {
713 return ( max - 1 ) * ( damage_ - 1 ) / ( max_damage() - 1 ) + 1;
714 }
715}

References damage_, and max_damage().

Referenced by Character::armor_absorb(), bash_resist(), bullet_resist(), activity_handlers::butcher_finish(), butchery_drops_harvest(), iuse::chainsaw_off(), crafting::complete_disassemble(), iuse::cs_lajatang_off(), cut_resist(), salvage_actor::cut_up(), damage_color(), vehicle_part::damage_level(), damage_melee(), damage_symbol(), veh_interact::do_repair(), durability_indicator(), gun_damage(), gun_dispersion(), avatar_funcs::gunmod_installation_odds(), monster::init_from_item(), vehicle_part::properties_to_item(), ready_to_revive(), repair_item_actor::repair_chance(), game::save_cyborg(), iuse::trimmer_off(), and fireweapon_off_actor::use().

◆ damage_melee()

int item::damage_melee ( damage_type  dt) const

Damage of given type caused when this item is used as melee weapon.

Definition at line 5213 of file item.cpp.

5214{
5215 assert( dt >= DT_NULL && dt < NUM_DT );
5216 if( is_null() ) {
5217 return 0;
5218 }
5219
5220 // effectiveness is reduced by 10% per damage level
5221 int res = type->melee[ dt ];
5222 res -= res * std::max( damage_level( 4 ), 0 ) * 0.1;
5223
5224 // apply type specific flags
5225 switch( dt ) {
5226 case DT_BASH:
5228 res *= 0.5;
5229 }
5230 break;
5231
5232 case DT_CUT:
5233 case DT_STAB:
5234 if( has_flag( flag_DIAMOND ) ) {
5235 res *= 1.3;
5236 }
5237 break;
5238
5239 default:
5240 break;
5241 }
5242
5243 // consider any melee gunmods
5244 if( is_gun() ) {
5245 const std::vector<const item *> &mods = gunmods();
5246 return std::accumulate( mods.begin(), mods.end(), res, [dt]( int last_max, const item * it ) {
5247 return it->has_flag( flag_MELEE_GUNMOD ) ? std::max( last_max, it->damage_melee( dt ) ) : last_max;
5248 } );
5249
5250 }
5251
5252 switch( dt ) {
5253 case DT_BASH:
5255 break;
5256 case DT_CUT:
5258 break;
5259 case DT_STAB:
5261 break;
5262 default:
5263 break;
5264 }
5265
5266 return std::max( res, 0 );
5267}
static const std::string flag_DIAMOND("DIAMOND")
static const std::string flag_REDUCED_BASHING("REDUCED_BASHING")
std::array< int, NUM_DT > melee
Damage output in melee for zero or more damage types.
Definition: itype.h:962

References bonus_from_enchantments_wielded(), damage_level(), DT_BASH, DT_CUT, DT_NULL, DT_STAB, flag_DIAMOND(), flag_REDUCED_BASHING(), gunmods(), has_flag(), is_gun(), is_null(), enchant_vals::ITEM_DAMAGE_BASH, enchant_vals::ITEM_DAMAGE_CUT, enchant_vals::ITEM_DAMAGE_STAB, itype::melee, NUM_DT, and type.

Referenced by base_damage_melee(), combat_info(), weapon_inventory_preset::deals_melee_damage(), character_effects::intimidation(), is_melee(), ma_requirements::is_valid_weapon(), melee_skill(), Character::melee_special_effects(), melee_train(), Character::power_rating(), activity_handlers::pulp_do_turn(), Character::reach_attack(), Character::roll_bash_damage(), Character::roll_cut_damage(), Character::roll_stab_damage(), smash(), and npc::smash_ability().

◆ damage_resist()

int item::damage_resist ( damage_type  dt,
bool  to_self = false 
) const

Resistance provided by this item against damage type given by an enum.

Definition at line 6396 of file item.cpp.

6397{
6398 switch( dt ) {
6399 case DT_NULL:
6400 case NUM_DT:
6401 return 0;
6402 case DT_TRUE:
6403 case DT_BIOLOGICAL:
6404 case DT_ELECTRIC:
6405 case DT_COLD:
6406 // Currently hardcoded:
6407 // Items can never be damaged by those types
6408 // But they provide 0 protection from them
6409 return to_self ? INT_MAX : 0;
6410 case DT_BASH:
6411 return bash_resist( to_self );
6412 case DT_CUT:
6413 return cut_resist( to_self );
6414 case DT_ACID:
6415 return acid_resist( to_self );
6416 case DT_STAB:
6417 return stab_resist( to_self );
6418 case DT_HEAT:
6419 return fire_resist( to_self );
6420 case DT_BULLET:
6421 return bullet_resist( to_self );
6422 default:
6423 debugmsg( "Invalid damage type: %d", dt );
6424 }
6425
6426 return 0;
6427}
int stab_resist(bool to_self=false) const
Definition: item.cpp:6117
@ DT_COLD
Definition: damage.h:29
@ DT_ELECTRIC
Definition: damage.h:30
@ DT_TRUE
Definition: damage.h:22
@ DT_ACID
Definition: damage.h:26
@ DT_BULLET
Definition: damage.h:31
@ DT_BIOLOGICAL
Definition: damage.h:23
@ DT_HEAT
Definition: damage.h:28

References acid_resist(), bash_resist(), bullet_resist(), cut_resist(), debugmsg, DT_ACID, DT_BASH, DT_BIOLOGICAL, DT_BULLET, DT_COLD, DT_CUT, DT_ELECTRIC, DT_HEAT, DT_NULL, DT_STAB, DT_TRUE, fire_resist(), NUM_DT, and stab_resist().

Referenced by Character::armor_absorb(), and resistances::resistances().

◆ damage_symbol()

std::string item::damage_symbol ( ) const

Provide prefix symbol for UI display dependent upon current item damage level.

Definition at line 6317 of file item.cpp.

6318{
6319 switch( damage_level( 4 ) ) {
6320 default:
6321 // reinforced
6322 return _( R"(++)" );
6323 case 0:
6324 return _( R"(||)" );
6325 case 1:
6326 return _( R"(|\)" );
6327 case 2:
6328 return _( R"(|.)" );
6329 case 3:
6330 return _( R"(\.)" );
6331 case 4:
6332 if( damage() >= max_damage() ) {
6333 return _( R"(XX)" );
6334 } else {
6335 return _( R"(..)" );
6336 }
6337
6338 }
6339}

References _, damage(), damage_level(), and max_damage().

Referenced by durability_indicator(), vehicle_part::name(), and veh_utils::repair_part().

◆ deactivate()

item & item::deactivate ( const Character ch = nullptr,
bool  alert = true 
)

Filter converting this instance to the inactive type If the item is either inactive or cannot be deactivated is a no-op.

Parameters
chcharacter currently possessing or acting upon the item (if any)
alertwhether to display any messages
Returns
same instance to allow method chaining

Definition at line 543 of file item.cpp.

544{
545 if( !active ) {
546 return *this; // no-op
547 }
548
549 if( is_tool() && type->tool->revert_to ) {
550 if( ch && alert && !type->tool->revert_msg.empty() ) {
551 ch->add_msg_if_player( m_info, _( type->tool->revert_msg ), tname() );
552 }
553 convert( *type->tool->revert_to );
554 active = false;
555
556 }
557 return *this;
558}
virtual void add_msg_if_player(const std::string &) const
Definition: creature.h:605
item & convert(const itype_id &new_type)
Filter converting this instance to another type preserving all other aspects.
Definition: item.cpp:536
@ m_info
Definition: enums.h:265

References _, active, Creature::add_msg_if_player(), alert, convert(), is_tool(), m_info, tname(), itype::tool, and type.

Referenced by iuse::note_bionics(), process_tool(), and fireweapon_on_actor::use().

◆ deserialize()

void item::deserialize ( JsonIn jsin)

Definition at line 2367 of file savegame_json.cpp.

2368{
2369 const JsonObject data = jsin.get_object();
2370 data.allow_omitted_members();
2371 io::JsonObjectInputArchive archive( data );
2372 io( archive );
2373 // made for fast forwarding time from 0.D to 0.E
2374 if( savegame_loading_version < 27 ) {
2376 }
2377 if( data.has_array( "contents" ) ) {
2378 std::list<item> items;
2379 data.read( "contents", items );
2380 contents = item_contents( items );
2381 } else {
2382 data.read( "contents", contents );
2383 }
2384
2385 // Sealed item migration: items with "unseals_into" set should always have contents
2387 convert( type->container->unseals_into );
2388 }
2389}
JsonObject get_object()
Definition: json.cpp:1432
bool has_array(const std::string &name) const
Definition: json.cpp:483
void allow_omitted_members() const
Definition: json.cpp:151
bool read(const std::string &name, T &t, bool throw_on_error=true) const
Definition: json.h:941
Input archive reading data from a Json object.
Definition: cata_io.h:185
void io(Archive &)
bool is_non_resealable_container() const
Whether removing this item's contents will permanently alter it.
Definition: item.cpp:6754
void legacy_fast_forward_time()
Definition: item.cpp:10044
int savegame_loading_version
Definition: savegame.cpp:64

References JsonObject::allow_omitted_members(), itype::container, contents, convert(), item_contents::empty(), JsonIn::get_object(), JsonObject::has_array(), io(), is_non_resealable_container(), legacy_fast_forward_time(), JsonObject::read(), savegame_loading_version, and type.

Referenced by item::craft_data::deserialize(), inventory::json_load_items(), monster::load(), and release_monster().

◆ destroyed_at_zero_charges()

bool item::destroyed_at_zero_charges ( ) const

Definition at line 6537 of file item.cpp.

6538{
6539 return ( is_ammo() || is_food() );
6540}

References is_ammo(), and is_food().

◆ detonate()

bool item::detonate ( const tripoint p,
std::vector< item > &  drops 
)

Detonates the item and adds remains (if any) to drops.

Returns true if the item actually detonated, potentially destroying other items and invalidating iterators. Should NOT be called on an item on the map, but on a local copy.

Definition at line 8770 of file item.cpp.

8771{
8772 if( type->explosion ) {
8774 return true;
8775 } else if( type->ammo && ( type->ammo->special_cookoff || type->ammo->cookoff ) ) {
8776 int charges_remaining = charges;
8777 const int rounds_exploded = rng( 1, charges_remaining );
8778 // Yank the exploding item off the map for the duration of the explosion
8779 // so it doesn't blow itself up.
8780 const islot_ammo &ammo_type = *type->ammo;
8781
8782 if( ammo_type.special_cookoff ) {
8783 // If it has a special effect just trigger it.
8784 apply_ammo_effects( p, ammo_type.ammo_effects, activated_by.get() );
8785 }
8786 charges_remaining -= rounds_exploded;
8787 if( charges_remaining > 0 ) {
8788 item temp_item = *this;
8789 temp_item.charges = charges_remaining;
8790 drops.push_back( temp_item );
8791 }
8792
8793 return true;
8794 } else if( !contents.empty() && ( !type->magazine || !type->magazine->protects_contents ) ) {
8795 std::vector<item *> removed_items;
8796 bool detonated = false;
8797 for( item *it : contents.all_items_top() ) {
8798 if( it->detonate( p, drops ) ) {
8799 removed_items.push_back( it );
8800 detonated = true;
8801 }
8802 }
8803 for( item *it : removed_items ) {
8804 remove_item( *it );
8805 }
8806 return detonated;
8807 }
8808
8809 return false;
8810}
safe_reference< Character > activated_by
Definition: item.h:2238
void explosion(const tripoint &p, Creature *source, float power, float factor, bool fire, int legacy_casing_mass, float)
Legacy explosion function.
Definition: explosion.cpp:1079
void apply_ammo_effects(const tripoint &p, const std::set< ammo_effect_str_id > &effects, Creature *source)
Definition: projectile.cpp:110
explosion_data explosion
Definition: itype.h:913

References activated_by, item_contents::all_items_top(), itype::ammo, ammo_type(), apply_ammo_effects(), charges, contents, item_contents::empty(), explosion_handler::explosion(), itype::explosion, itype::magazine, visitable< item >::remove_item(), rng(), and type.

Referenced by map::process_fields_in_submap(), and map::smash_items().

◆ disassembly_info()

void item::disassembly_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3194 of file item.cpp.

3196{
3198 return;
3199 }
3201 return;
3202 }
3203
3205 const requirement_data &req = dis.disassembly_requirements();
3206 if( !req.is_empty() ) {
3207 const std::string approx_time = to_string_approx( time_duration::from_turns( dis.time / 100 ) );
3208
3210 const std::string comps_str = enumerate_as_string( comps_list.begin(), comps_list.end(),
3211 []( const std::vector<item_comp> &comp_opts ) {
3212 return comp_opts.front().to_string();
3213 } );
3214
3215 std::vector<std::string> reqs_list;
3216 const requirement_data::alter_tool_comp_vector &tools_list = req.get_tools();
3217 for( const std::vector<tool_comp> &it : tools_list ) {
3218 if( !it.empty() ) {
3219 reqs_list.push_back( it.front().to_string() );
3220 }
3221 }
3223 for( const std::vector<quality_requirement> &it : quals_list ) {
3224 if( !it.empty() ) {
3225 reqs_list.push_back( it.front().to_colored_string() );
3226 }
3227 }
3228
3229 std::string descr;
3230 if( reqs_list.empty() ) {
3231 //~ 1 is approx. time (e.g. 'about 5 minutes'), 2 is a list of items
3232 descr = string_format( _( "<bold>Disassembly</bold> takes %1$s and might yield: %2$s." ),
3233 approx_time, comps_str );
3234 } else {
3235 const std::string reqs_str = enumerate_as_string( reqs_list );
3236 descr = string_format(
3237 //~ 1 is approx. time, 2 is a list of items and tools with qualities, 3 is a list of items.
3238 //~ Bold text in the middle makes it easier to see where the second list starts.
3239 _( "<bold>Disassembly</bold> takes %1$s, requires %2$s and <bold>might yield</bold>: %3$s." ),
3240 approx_time, reqs_str, comps_str );
3241 }
3242
3244 info.push_back( iteminfo( "DESCRIPTION", descr ) );
3245 }
3246}
std::string to_string_approx(const time_duration &dur, const bool verbose)
Returns approximate duration.
Definition: calendar.cpp:361
static const recipe & get_uncraft(const itype_id &id)
Returns disassembly recipe (or null recipe if no match)
Definition: recipe.h:35
requirement_data disassembly_requirements() const
If recipe can be used for disassembly fetch the combined requirements.
Definition: recipe.h:96
int time
Definition: recipe.h:61
static constexpr time_duration from_turns(const T t)
Named constructors to get a duration representing a multiple of the named time units.
Definition: calendar.h:204
@ DESCRIPTION_COMPONENTS_DISASSEMBLE
The *_vector members represent list of alternatives requirements: alter_tool_comp_vector = { * { { a,...
Definition: requirements.h:215
const alter_tool_comp_vector & get_tools() const
const alter_item_comp_vector & get_components() const
std::vector< std::vector< quality_requirement > > alter_quali_req_vector
Definition: requirements.h:222
bool is_empty() const
empty requirements are not necessary null
Definition: requirements.h:247
std::vector< std::vector< item_comp > > alter_item_comp_vector
Definition: requirements.h:223
const alter_quali_req_vector & get_qualities() const
std::vector< std::vector< tool_comp > > alter_tool_comp_vector
Definition: requirements.h:221

References _, components, DESCRIPTION_COMPONENTS_DISASSEMBLE, DESCRIPTION_COMPONENTS_MADEFROM, recipe::disassembly_requirements(), enumerate_as_string(), time_duration::from_turns(), requirement_data::get_components(), requirement_data::get_qualities(), requirement_data::get_tools(), recipe_dictionary::get_uncraft(), info(), insert_separation_line(), requirement_data::is_empty(), string_format(), iteminfo_query::test(), recipe::time, to_string_approx(), and typeId().

Referenced by info().

◆ display_money()

std::string item::display_money ( unsigned int  quantity,
unsigned int  total,
const std::optional< unsigned int > &  selected = std::nullopt 
) const

Definition at line 4824 of file item.cpp.

4826{
4827 if( selected ) {
4828 //~ This is a string to display the selected and total amount of money in a stack of cash cards.
4829 //~ %1$s is the display name of cash cards.
4830 //~ %2$s is the total amount of money.
4831 //~ %3$s is the selected amount of money.
4832 //~ Example: "cash cards $15.35 of $20.48"
4833 return string_format( pgettext( "cash card and money", "%1$s %3$s of %2$s" ), tname( quantity ),
4834 format_money( total ), format_money( *selected ) );
4835 } else {
4836 //~ This is a string to display the total amount of money in a stack of cash cards.
4837 //~ %1$s is the display name of cash cards.
4838 //~ %2$s is the total amount of money on the cash cards.
4839 //~ Example: "cash cards $20.48"
4840 return string_format( pgettext( "cash card and money", "%1$s %2$s" ), tname( quantity ),
4841 format_money( total ) );
4842 }
4843}
std::string format_money(int cents)
Definition: output.h:932
const char * pgettext(const char *context, const char *msgid)

References format_money(), pgettext(), string_format(), and tname().

Referenced by inventory_selector_preset::get_caption(), and selection_column_preset::get_caption().

◆ display_name()

std::string item::display_name ( unsigned int  quantity = 1) const

Returns the item name and the charges or contained charges (if the item can have charges at all).

Calls tname with given quantity and with_prefix being true.

Definition at line 4845 of file item.cpp.

4846{
4847 std::string name = tname( quantity );
4848 std::string sidetxt;
4849 std::string amt;
4850
4851 switch( get_side() ) {
4852 case side::BOTH:
4853 case side::num_sides:
4854 break;
4855 case side::LEFT:
4856 sidetxt = string_format( " (%s)", _( "left" ) );
4857 break;
4858 case side::RIGHT:
4859 sidetxt = string_format( " (%s)", _( "right" ) );
4860 break;
4861 }
4862 avatar &you = get_avatar();
4863 int amount = 0;
4864 int max_amount = 0;
4865 bool has_item = is_container() && contents.num_item_stacks() == 1;
4866 bool has_ammo = is_ammo_container() && contents.num_item_stacks() == 1;
4867 bool contains = has_item || has_ammo;
4868 bool show_amt = false;
4869 // We should handle infinite charges properly in all cases.
4870 if( contains ) {
4871 amount = contents.front().charges;
4873 } else if( is_book() && get_chapters() > 0 ) {
4874 // a book which has remaining unread chapters
4875 amount = get_remaining_chapters( you );
4876 } else if( ammo_capacity() > 0 ) {
4877 // anything that can be reloaded including tools, magazines, guns and auxiliary gunmods
4878 // but excluding bows etc., which have ammo, but can't be reloaded
4879 amount = ammo_remaining();
4880 max_amount = ammo_capacity();
4881 show_amt = !has_flag( flag_RELOAD_AND_SHOOT );
4882 } else if( count_by_charges() && !has_infinite_charges() ) {
4883 // A chargeable item
4884 amount = charges;
4885 max_amount = ammo_capacity();
4886 } else if( is_battery() ) {
4887 show_amt = true;
4888 amount = to_joule( energy_remaining() );
4889 max_amount = to_joule( type->battery->max_capacity );
4890 }
4891
4892 std::string ammotext;
4893 if( ( ( is_gun() && ammo_required() ) || is_magazine() ) && get_option<bool>( "AMMO_IN_NAMES" ) ) {
4894 if( !ammo_current().is_null() ) {
4895 ammotext = ammo_current()->nname( 1 );
4896 } else {
4897 ammotext = ammotype( *ammo_types().begin() )->name();
4898 }
4899 }
4900
4901 if( amount || show_amt ) {
4902 if( is_money() ) {
4903 amt = string_format( " $%.2f", amount / 100.0 );
4904 } else {
4905 if( !ammotext.empty() ) {
4906 ammotext = " " + ammotext;
4907 }
4908
4909 if( max_amount != 0 ) {
4910 amt = string_format( " (%i/%i%s)", amount, max_amount, ammotext );
4911 } else {
4912 amt = string_format( " (%i%s)", amount, ammotext );
4913 }
4914 }
4915 } else if( !ammotext.empty() ) {
4916 amt = " (" + ammotext + ")";
4917 }
4918
4919 // HACK: This is a hack to prevent possible crashing when displaying maps as items during character creation
4921 // TODO: fix point types
4922 tripoint map_pos_omt =
4923 get_var( "reveal_map_center_omt", you.global_omt_location().raw() );
4924 tripoint_abs_sm map_pos =
4925 project_to<coords::sm>( tripoint_abs_omt( map_pos_omt ) );
4926 const city *c = overmap_buffer.closest_city( map_pos ).city;
4927 if( c != nullptr ) {
4928 name = string_format( "%s %s", c->name, name );
4929 }
4930 }
4931
4932 return string_format( "%s%s%s", name, sidetxt, amt );
4933}
@ num_sides
tripoint_abs_omt global_omt_location() const
Returns the location of the player in global overmap terrain coordinates.
Definition: character.cpp:6268
constexpr Point & raw()
Definition: coordinates.h:111
bool is_ammo_container() const
Definition: item.cpp:6687
bool has_infinite_charges() const
Definition: item.cpp:9990
itype_id ammo_current() const
Specific ammo type, returns "null" if item is neither ammo nor loaded with any.
Definition: item.cpp:7576
bool is_map() const
Definition: item.cpp:6739
units::energy energy_remaining() const
Quantity of energy currently loaded in tool or battery.
Definition: item.cpp:7390
int charges_per_volume(const units::volume &vol) const
Number of (charges of) this item that fit into the given volume.
Definition: item.cpp:867
units::volume get_container_capacity() const
It returns the total capacity (volume) of the container for liquids.
Definition: item.cpp:8417
side get_side() const
Returns side item currently worn on.
Definition: item.cpp:811
int get_chapters() const
How many chapters the book has (if any).
Definition: item.cpp:7114
city_reference closest_city(const tripoint_abs_sm &center)
Find the closest city.
bool has_item(const item &it) const
Returns true if this visitable instance contains the item.
Definition: visitable.cpp:95
coords::coord_point< tripoint, coords::origin::abs, coords::omt > tripoint_abs_omt
Definition: coordinates.h:493
static const std::string flag_RELOAD_AND_SHOOT("RELOAD_AND_SHOOT")
const time_point turn_zero
Represents time point 0.
Definition: calendar.cpp:26
overmapbuffer overmap_buffer
const struct city * city
The city itself, points into overmap::cities.
Definition: overmapbuffer.h:81
Definition: overmap.h:55

References _, ammo_capacity(), ammo_current(), ammo_remaining(), ammo_required(), ammo_types(), itype::battery, BOTH, c, charges, charges_per_volume(), city_reference::city, overmapbuffer::closest_city(), contains, contents, count_by_charges(), energy_remaining(), flag_RELOAD_AND_SHOOT(), item_contents::front(), get_avatar(), get_chapters(), get_container_capacity(), get_remaining_chapters(), get_side(), get_var(), Character::global_omt_location(), has_flag(), has_infinite_charges(), visitable< item >::has_item(), is_ammo_container(), is_battery(), is_book(), is_container(), is_gun(), is_magazine(), is_map(), is_money(), is_null(), LEFT, ammunition_type::name(), om_direction::name(), itype::nname(), item_contents::num_item_stacks(), num_sides, overmap_buffer, coords::coord_point< Point, Origin, Scale >::raw(), RIGHT, string_format(), tname(), units::to_joule(), calendar::turn, calendar::turn_zero, and type.

Referenced by act_vehicle_unload_fuel(), monexamine::add_armor(), monexamine::attach_bag_to(), veh_interact::can_remove_part(), game_menus::inv::container_for(), inventory_selector_preset::get_caption(), selection_column_preset::get_caption(), liquid_handler::get_liquid_target(), game::handle_action(), handle_problematic_pickup(), pickup::handle_spillable_contents(), inscribe_actor::item_inscription(), game::list_items(), pick_one_up(), pickup::pick_up(), trading_window::update_win(), and musical_instrument_actor::use().

◆ display_stacked_with()

bool item::display_stacked_with ( const item rhs,
bool  check_components = false 
) const

Whether two items should stack when displayed in a inventory menu.

This is different from stacks_with, when two previously non-stackable items are now stackable and mergeable because, for example, they reaches the same temperature. This is necessary to avoid misleading stacks like "3 items-count-by-charge (5)".

Definition at line 887 of file item.cpp.

888{
889 return !count_by_charges() && stacks_with( rhs, check_components );
890}
bool stacks_with(const item &rhs, bool check_components=false, bool skip_type_check=false) const
Definition: item.cpp:892

References count_by_charges(), and stacks_with().

Referenced by pickup::stack_for_pickup_ui().

◆ dps() [1/2]

std::map< std::string, double > item::dps ( bool  for_display,
bool  for_calc 
) const

Definition at line 1446 of file item.cpp.

1447{
1448 return dps( for_display, for_calc, get_avatar() );
1449}

References dps(), and get_avatar().

◆ dps() [2/2]

std::map< std::string, double > item::dps ( bool  for_display,
bool  for_calc,
const player guy 
) const

calculate effective dps against a stock set of monsters.

by default, assume g->u is wielding for_display - include monsters intended for display purposes for_calc - include monsters intended for evaluation purposes for_display and for_calc are inclusive

Definition at line 1431 of file item.cpp.

1433{
1434 std::map<std::string, double> results;
1435 for( const std::pair<translation, dps_comp_data> &comp_mon : dps_comp_monsters ) {
1436 if( ( comp_mon.second.display != for_display ) &&
1437 ( comp_mon.second.evaluate != for_calc ) ) {
1438 continue;
1439 }
1440 monster test_mon = monster( comp_mon.second.mon_id );
1441 results[ comp_mon.first.translated() ] = effective_dps( guy, test_mon );
1442 }
1443 return results;
1444}
double effective_dps(const player &guy, const monster &mon) const
Calculate the item's effective damage per second past armor when wielded by a character against a mon...
Definition: item.cpp:1328
static const std::vector< std::pair< translation, dps_comp_data > > dps_comp_monsters
Definition: item.cpp:1424

References dps_comp_monsters, and effective_dps().

Referenced by average_dps(), combat_info(), dps(), and ideal_ranged_dps().

◆ durability_indicator()

std::string item::durability_indicator ( bool  include_intact = false) const

Provides a prefix for the durability state of the item.

with ITEM_HEALTH_BAR enabled, returns a symbol with color tag already applied. Otherwise, returns an adjective. if include_intact is true, this provides a string for the corner case of a player with ITEM_HEALTH_BAR disabled, but we need still a string for some reason.

Definition at line 6341 of file item.cpp.

6342{
6343 std::string outputstring;
6344
6345 if( damage() < 0 ) {
6346 if( get_option<bool>( "ITEM_HEALTH_BAR" ) ) {
6347 outputstring = colorize( damage_symbol() + "\u00A0", damage_color() );
6348 } else if( is_gun() ) {
6349 outputstring = pgettext( "damage adjective", "accurized " );
6350 } else {
6351 outputstring = pgettext( "damage adjective", "reinforced " );
6352 }
6353 } else if( has_flag( flag_CORPSE ) ) {
6354 if( damage() > 0 ) {
6355 switch( damage_level( 4 ) ) {
6356 case 1:
6357 outputstring = pgettext( "damage adjective", "bruised " );
6358 break;
6359 case 2:
6360 outputstring = pgettext( "damage adjective", "damaged " );
6361 break;
6362 case 3:
6363 outputstring = pgettext( "damage adjective", "mangled " );
6364 break;
6365 default:
6366 outputstring = pgettext( "damage adjective", "pulped " );
6367 break;
6368 }
6369 }
6370 } else if( get_option<bool>( "ITEM_HEALTH_BAR" ) ) {
6371 outputstring = colorize( damage_symbol() + "\u00A0", damage_color() );
6372 } else {
6373 outputstring = string_format( "%s ", get_base_material().dmg_adj( damage_level( 4 ) ) );
6374 if( include_intact && outputstring == " " ) {
6375 outputstring = _( "fully intact " );
6376 }
6377 }
6378
6379 return outputstring;
6380}
std::string damage_symbol() const
Provide prefix symbol for UI display dependent upon current item damage level.
Definition: item.cpp:6317
const material_type & get_base_material() const
Get the basic (main) material of this item.
Definition: item.cpp:7176
nc_color damage_color() const
Provide color for UI display dependent upon current item damage level.
Definition: item.cpp:6288

References _, colorize(), damage(), damage_color(), damage_level(), damage_symbol(), flag_CORPSE(), get_base_material(), has_flag(), is_gun(), pgettext(), and string_format().

Referenced by colorized_item_name(), damage_item(), iuse::gun_repair(), repair_item_actor::repair(), and tname().

◆ effective_dps()

double item::effective_dps ( const player guy,
const monster mon 
) const

Calculate the item's effective damage per second past armor when wielded by a character against a monster.

Definition at line 1328 of file item.cpp.

1329{
1330 const float mon_dodge = mon.get_dodge();
1331 float base_hit = guy.get_dex() / 4.0f + guy.get_hit_weapon( *this );
1332 base_hit *= std::max( 0.25f, 1.0f - guy.encumb( bp_torso ) / 100.0f );
1333 float mon_defense = mon_dodge + mon.size_melee_penalty() / 5.0;
1334 constexpr double hit_trials = 10000.0;
1335 const int rng_mean = std::max( std::min( static_cast<int>( base_hit - mon_defense ), 20 ),
1336 -20 ) + 20;
1337 double num_all_hits = hits_by_accuracy[ rng_mean ];
1338 /* critical hits have two chances to occur: triple critical hits happen much less frequently,
1339 * and double critical hits can only occur if a hit roll is more than 1.5 * monster dodge.
1340 * Not the hit roll used to determine the attack, another one.
1341 * the way the math works, some percentage of the total hits are eligible to be double
1342 * critical hits, and the rest are eligible to be triple critical hits, but in each case,
1343 * only some small percent of them actually become critical hits.
1344 */
1345 const int rng_high_mean = std::max( std::min( static_cast<int>( base_hit - 1.5 * mon_dodge ),
1346 20 ), -20 ) + 20;
1347 double num_high_hits = hits_by_accuracy[ rng_high_mean ] * num_all_hits / hit_trials;
1348 double double_crit_chance = guy.crit_chance( 4, 0, *this );
1349 double crit_chance = guy.crit_chance( 0, 0, *this );
1350 double num_low_hits = std::max( 0.0, num_all_hits - num_high_hits );
1351
1352 double moves_per_attack = guy.attack_cost( *this );
1353 // attacks that miss do no damage but take time
1354 double total_moves = ( hit_trials - num_all_hits ) * moves_per_attack;
1355 double total_damage = 0.0;
1356 double num_crits = std::min( num_low_hits * crit_chance + num_high_hits * double_crit_chance,
1357 num_all_hits );
1358 // critical hits are counted separately
1359 double num_hits = num_all_hits - num_crits;
1360 // sum average damage past armor and return the number of moves required to achieve
1361 // that damage
1362 const auto calc_effective_damage = [ &, moves_per_attack]( const double num_strikes,
1363 const bool crit, const player & guy, const monster & mon ) {
1364 monster temp_mon = mon;
1365 double subtotal_damage = 0;
1366 damage_instance base_damage;
1367 guy.roll_all_damage( crit, base_damage, true, *this );
1368 damage_instance dealt_damage = base_damage;
1369 temp_mon.absorb_hit( bodypart_id( "torso" ), dealt_damage );
1370 dealt_damage_instance dealt_dams;
1371 for( const damage_unit &dmg_unit : dealt_damage.damage_units ) {
1372 int cur_damage = 0;
1373 int total_pain = 0;
1374 temp_mon.deal_damage_handle_type( dmg_unit, bodypart_id( "torso" ), cur_damage, total_pain );
1375 if( cur_damage > 0 ) {
1376 dealt_dams.dealt_dams[ dmg_unit.type ] += cur_damage;
1377 }
1378 }
1379 double damage_per_hit = dealt_dams.total_damage();
1380 subtotal_damage = damage_per_hit * num_strikes;
1381 double subtotal_moves = moves_per_attack * num_strikes;
1382
1383 if( has_technique( rapid_strike ) ) {
1384 monster temp_rs_mon = mon;
1385 damage_instance rs_base_damage;
1386 guy.roll_all_damage( crit, rs_base_damage, true, *this );
1387 damage_instance dealt_rs_damage = rs_base_damage;
1388 for( damage_unit &dmg_unit : dealt_rs_damage.damage_units ) {
1389 dmg_unit.damage_multiplier *= 0.66;
1390 }
1391 temp_rs_mon.absorb_hit( bodypart_id( "torso" ), dealt_rs_damage );
1392 dealt_damage_instance rs_dealt_dams;
1393 for( const damage_unit &dmg_unit : dealt_rs_damage.damage_units ) {
1394 int cur_damage = 0;
1395 int total_pain = 0;
1396 temp_rs_mon.deal_damage_handle_type( dmg_unit, bodypart_id( "torso" ), cur_damage, total_pain );
1397 if( cur_damage > 0 ) {
1398 rs_dealt_dams.dealt_dams[ dmg_unit.type ] += cur_damage;
1399 }
1400 }
1401 double rs_damage_per_hit = rs_dealt_dams.total_damage();
1402 subtotal_moves *= 0.5;
1403 subtotal_damage *= 0.5;
1404 subtotal_moves += moves_per_attack * num_strikes * 0.33;
1405 subtotal_damage += rs_damage_per_hit * num_strikes * 0.5;
1406 }
1407 return std::make_pair( subtotal_moves, subtotal_damage );
1408 };
1409 std::pair<double, double> crit_summary = calc_effective_damage( num_crits, true, guy, mon );
1410 total_moves += crit_summary.first;
1411 total_damage += crit_summary.second;
1412 std::pair<double, double> summary = calc_effective_damage( num_hits, false, guy, mon );
1413 total_moves += summary.first;
1414 total_damage += summary.second;
1415 return total_damage * to_moves<double>( 1_seconds ) / total_moves;
1416}
int_id< body_part_type > bodypart_id
Definition: bodypart.h:24
virtual int get_dex() const
Definition: character.cpp:4092
float get_hit_weapon(const item &weap) const
Gets melee accuracy component from weapon+skills.
Definition: melee.cpp:334
int encumb(body_part bp) const
Returns ENC provided by armor, etc.
Definition: character.cpp:4025
int size_melee_penalty() const
Definition: creature.cpp:483
bool has_technique(const matec_id &tech) const
Whether the item supports a specific martial art technique (either through its type,...
Definition: item.cpp:5464
void deal_damage_handle_type(const damage_unit &du, bodypart_id bp, int &damage, int &pain) override
Definition: monster.cpp:1621
float get_dodge() const override
Definition: monster.cpp:2002
void absorb_hit(const bodypart_id &bp, damage_instance &dam) override
Definition: monster.cpp:1404
Definition: player.h:84
static const double hits_by_accuracy[41]
Definition: item.cpp:1316
static const matec_id rapid_strike("RAPID")
damage_type type
Definition: damage.h:36
float damage_multiplier
Definition: damage.h:40
std::array< int, NUM_DT > dealt_dams
Definition: damage.h:86
int total_damage() const
Definition: damage.cpp:180

References monster::absorb_hit(), Character::attack_cost(), bp_torso, Character::crit_chance(), damage_unit::damage_multiplier, damage_instance::damage_units, monster::deal_damage_handle_type(), dealt_damage_instance::dealt_dams, Character::encumb(), Character::get_dex(), monster::get_dodge(), Character::get_hit_weapon(), has_technique(), hits_by_accuracy, rapid_strike, Character::roll_all_damage(), Creature::size_melee_penalty(), dealt_damage_instance::total_damage(), and damage_unit::type.

Referenced by dps().

◆ energy_remaining()

units::energy item::energy_remaining ( ) const

Quantity of energy currently loaded in tool or battery.

Definition at line 7390 of file item.cpp.

7391{
7392 if( is_battery() ) {
7393 return energy;
7394 }
7395
7396 return 0_J;
7397}
units::energy energy
Definition: item.h:2200

References energy, and is_battery().

Referenced by display_name(), mod_energy(), process_vehicle_items(), and charger_tile::update_internal().

◆ engine_displacement()

int item::engine_displacement ( ) const

for combustion engines the displacement (cc)

Definition at line 4137 of file item.cpp.

4138{
4139 return type->engine ? type->engine->displacement : 0;
4140}
cata::value_ptr< islot_engine > engine
Definition: itype.h:824

References itype::engine, and type.

Referenced by veh_interact::display_details(), vehicle_part::name(), vehicle::part_vpower_w(), and tname().

◆ erase_var()

void item::erase_var ( const std::string &  name)

◆ faults_potential()

std::set< fault_id > item::faults_potential ( ) const

What faults can potentially occur with this item?

Definition at line 6829 of file item.cpp.

6830{
6831 std::set<fault_id> res;
6832 res.insert( type->faults.begin(), type->faults.end() );
6833 return res;
6834}
std::set< fault_id > faults
What faults (if any) can occur.
Definition: itype.h:985

References itype::faults, and type.

Referenced by vehicle_part::faults_potential(), ranged::handle_gun_damage(), and examine_item_menu::rate_action_mend().

◆ fill_with()

void item::fill_with ( item liquid,
int  amount = INFINITE_CHARGES 
)

Fill item with liquid up to its capacity.

This works for guns and tools that accept liquid ammo.

Parameters
liquidLiquid to fill the container with.
amountAmount to fill item with, capped by remaining capacity

Definition at line 8584 of file item.cpp.

8585{
8586 amount = std::min( get_remaining_capacity_for_liquid( liquid, true ),
8587 std::min( amount, liquid.charges ) );
8588 if( amount <= 0 ) {
8589 return;
8590 }
8591
8592 if( !is_container() ) {
8593 if( !is_reloadable_with( liquid.typeId() ) ) {
8594 debugmsg( "Tried to fill %s which is not a container and can't be reloaded with %s.",
8595 tname(), liquid.tname() );
8596 return;
8597 }
8598 ammo_set( liquid.typeId(), ammo_remaining() + amount );
8599 } else if( is_food_container() ) {
8600 item &cts = contents.front();
8601 // Use maximum rot between the two
8602 cts.set_relative_rot( std::max( cts.get_relative_rot(),
8603 liquid.get_relative_rot() ) );
8604 cts.mod_charges( amount );
8605 } else if( !is_container_empty() ) {
8606 // if container already has liquid we need to set the amount
8607 item &cts = contents.front();
8608 cts.mod_charges( amount );
8609 } else {
8610 item liquid_copy( liquid );
8611 liquid_copy.charges = amount;
8612 put_in( liquid_copy );
8613 }
8614
8615 liquid.mod_charges( -amount );
8617}
bool is_reloadable_with(const itype_id &ammo) const
Returns true if this item can be reloaded with specified ammo type at this moment.
Definition: item.cpp:6896
void mod_charges(int mod)
Modify the charges of this item, only use for items counted by charges! The item must have enough cha...
Definition: item.cpp:9750
void on_contents_changed()
Callback when contents of the item are affected in any way other than just processing.
Definition: item.cpp:4558
int get_remaining_capacity_for_liquid(const item &liquid, bool allow_bucket=false, std::string *err=nullptr) const
How much more of this liquid (in charges) can be put in this container.
Definition: item.cpp:8446

References ammo_remaining(), ammo_set(), charges, contents, debugmsg, item_contents::front(), get_relative_rot(), get_remaining_capacity_for_liquid(), is_container(), is_container_empty(), is_food_container(), is_reloadable_with(), mod_charges(), on_contents_changed(), put_in(), set_relative_rot(), tname(), and typeId().

Referenced by veh_interact::complete_vehicle(), vehicle_part::fill_with(), advanced_inventory::move_content(), Character::pour_into(), and reload().

◆ final_info()

void item::final_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3646 of file item.cpp.

3648{
3649 if( is_null() ) {
3650 return;
3651 }
3652
3653 // TODO: Remove
3654 const iteminfo_query *parts = &parts_ref;
3655
3656 const std::string space = " ";
3657
3659
3660 if( parts->test( iteminfo_parts::BASE_RIGIDITY ) ) {
3661 if( !type->rigid ) {
3662 info.emplace_back( "BASE",
3663 _( "* This item is <info>not rigid</info>. Its"
3664 " volume and encumbrance increase with contents." ) );
3665 }
3666 }
3667
3669 if( !conductive() ) {
3670 info.push_back( iteminfo( "BASE", _( "* This item <good>does not "
3671 "conduct</good> electricity." ) ) );
3672 } else if( has_flag( flag_CONDUCTIVE ) ) {
3673 info.push_back( iteminfo( "BASE",
3674 _( "* This item effectively <bad>conducts</bad> "
3675 "electricity, as it has no guard." ) ) );
3676 } else {
3677 info.push_back( iteminfo( "BASE", _( "* This item <bad>conducts</bad> electricity." ) ) );
3678 }
3679 }
3680
3681 avatar &you = get_avatar();
3682 if( is_armor() && you.has_trait( trait_WOOLALLERGY ) &&
3683 ( made_of( material_id( "wool" ) ) || has_own_flag( "wooled" ) ) ) {
3684 info.push_back( iteminfo( "DESCRIPTION",
3685 _( "* This clothing will give you an <bad>allergic "
3686 "reaction</bad>." ) ) );
3687 }
3688
3689 if( parts->test( iteminfo_parts::DESCRIPTION_FLAGS ) ) {
3690 // concatenate base and acquired flags...
3691 std::vector<std::string> flags;
3692 std::set_union( type->get_flags().begin(), type->get_flags().end(),
3693 get_flags().begin(), get_flags().end(),
3694 std::back_inserter( flags ) );
3695
3696 // ...and display those which have an info description
3697 for( const std::string &e : flags ) {
3698 const json_flag &f = json_flag::get( e );
3699 if( !f.info().empty() ) {
3700 info.emplace_back( "DESCRIPTION", string_format( "* %s", _( f.info() ) ) );
3701 }
3702 }
3703 }
3704
3705 armor_fit_info( info, parts, batch, debug );
3706
3707 if( is_tool() ) {
3709 info.push_back( iteminfo( "DESCRIPTION",
3710 _( "* This tool can draw power from a <info>Bionic Armor Interface</info>" ) ) );
3711 }
3713 info.push_back( iteminfo( "DESCRIPTION",
3714 _( "* This tool uses a <info>universal power supply</info> "
3715 "and is <neutral>not compatible</neutral> with "
3716 "<info>standard batteries</info>." ) ) );
3717 } else if( has_flag( flag_RECHARGE ) && has_flag( flag_NO_RELOAD ) &&
3719 info.push_back( iteminfo( "DESCRIPTION",
3720 _( "* This tool has a <info>rechargeable power cell</info> "
3721 "and is <neutral>not compatible</neutral> with "
3722 "<info>standard batteries</info>." ) ) );
3723 } else if( has_flag( flag_RECHARGE ) &&
3725 info.push_back( iteminfo( "DESCRIPTION",
3726 _( "* This tool has a <info>rechargeable power cell</info> "
3727 "and can be recharged in any <neutral>UPS-compatible "
3728 "recharging station</neutral>. You could charge it with "
3729 "<info>standard batteries</info>, but unloading it is "
3730 "impossible." ) ) );
3731 } else if( has_flag( flag_USES_BIONIC_POWER ) ) {
3732 info.emplace_back( "DESCRIPTION",
3733 _( "* This tool <info>runs on bionic power</info>." ) );
3734 }
3735 }
3736
3739 if( has_flag( flag_RADIO_MOD ) ) {
3740 info.emplace_back( "DESCRIPTION",
3741 _( "* This item has been modified to listen to <info>radio "
3742 "signals</info>. It can still be activated manually." ) );
3743 } else {
3744 info.emplace_back( "DESCRIPTION",
3745 _( "* This item can only be activated by a <info>radio "
3746 "signal</info>." ) );
3747 }
3748
3749 std::string signame;
3750 if( has_flag( flag_RADIOSIGNAL_1 ) ) {
3751 signame = "<color_c_red>red</color> radio signal.";
3752 } else if( has_flag( flag_RADIOSIGNAL_2 ) ) {
3753 signame = "<color_c_blue>blue</color> radio signal.";
3754 } else if( has_flag( flag_RADIOSIGNAL_3 ) ) {
3755 signame = "<color_c_green>green</color> radio signal.";
3756 }
3758 info.emplace_back( "DESCRIPTION",
3759 string_format( _( "* It will be activated by the %s." ),
3760 signame ) );
3761 }
3762
3765 info.emplace_back( "DESCRIPTION",
3766 _( "* Activating this item with a <info>radio signal</info> will "
3767 "<neutral>detonate</neutral> it immediately." ) );
3768 }
3769 }
3770
3771 bionic_info( info, parts, batch, debug );
3772
3773 if( is_gun() && has_flag( flag_FIRE_TWOHAND ) &&
3775 info.push_back( iteminfo( "DESCRIPTION",
3776 _( "* This weapon needs <info>two free hands</info> "
3777 "to fire." ) ) );
3778 }
3779
3782 info.push_back( iteminfo( "DESCRIPTION",
3783 _( "* This mod <bad>obscures sights</bad> of the "
3784 "base weapon." ) ) );
3785 }
3786
3787 if( is_gunmod() && has_flag( flag_CONSUMABLE ) &&
3789 info.push_back( iteminfo( "DESCRIPTION",
3790 _( "* This mod might <bad>suffer wear</bad> when firing "
3791 "the base weapon." ) ) );
3792 }
3793
3796 info.push_back( iteminfo( "DESCRIPTION",
3797 _( "* The casing of this item has <neutral>cracked</neutral>, "
3798 "revealing an <info>ominous green glow</info>." ) ) );
3799 }
3800
3803 info.push_back( iteminfo( "DESCRIPTION",
3804 _( "* This object is <neutral>surrounded</neutral> by a "
3805 "<info>sickly green glow</info>." ) ) );
3806 }
3807
3808 if( is_brewable() || ( !contents.empty() && contents.front().is_brewable() ) ) {
3809 const item &brewed = !is_brewable() ? contents.front() : *this;
3811 const time_duration btime = brewed.brewing_time();
3812 int btime_i = to_days<int>( btime );
3813 if( btime <= 2_days ) {
3814 btime_i = to_hours<int>( btime );
3815 info.push_back( iteminfo( "DESCRIPTION",
3816 string_format( vgettext( "* Once set in a vat, this "
3817 "will ferment in around %d hour.",
3818 "* Once set in a vat, this will ferment in "
3819 "around %d hours.", btime_i ), btime_i ) ) );
3820 } else {
3821 info.push_back( iteminfo( "DESCRIPTION",
3822 string_format( vgettext( "* Once set in a vat, this "
3823 "will ferment in around %d day.",
3824 "* Once set in a vat, this will ferment in "
3825 "around %d days.", btime_i ), btime_i ) ) );
3826 }
3827 }
3829 for( const itype_id &res : brewed.brewing_results() ) {
3830 info.push_back( iteminfo( "DESCRIPTION",
3831 string_format( _( "* Fermenting this will produce "
3832 "<neutral>%s</neutral>." ),
3833 nname( res, brewed.charges ) ) ) );
3834 }
3835 }
3836 }
3837
3839 for( const fault_id &e : faults ) {
3840 //~ %1$s is the name of a fault and %2$s is the description of the fault
3841 info.emplace_back( "DESCRIPTION", string_format( _( "* <bad>%1$s</bad>. %2$s" ),
3842 e.obj().name(), e.obj().description() ) );
3843 }
3844 }
3845
3846 // does the item fit in any holsters?
3847 std::vector<const itype *> holsters = item_controller->find( [this]( const itype & e ) {
3848 if( !e.can_use( "holster" ) ) {
3849 return false;
3850 }
3851 const holster_actor *ptr = dynamic_cast<const holster_actor *>
3852 ( e.get_use( "holster" )->get_actor_ptr() );
3853 return ptr->can_holster( *this );
3854 } );
3855
3856 if( !holsters.empty() && parts->test( iteminfo_parts::DESCRIPTION_HOLSTERS ) ) {
3858 info.emplace_back( "DESCRIPTION", _( "<bold>Can be stored in</bold>: " ) +
3859 enumerate_as_string( holsters.begin(), holsters.end(),
3860 []( const itype * e ) {
3861 return e->nname( 1 );
3862 } ) );
3863 }
3864
3866 for( auto &u : type->use_methods ) {
3867 const delayed_transform_iuse *tt = dynamic_cast<const delayed_transform_iuse *>
3868 ( u.second.get_actor_ptr() );
3869 if( tt == nullptr ) {
3870 continue;
3871 }
3872 const int time_to_do = tt->time_to_do( *this );
3873 if( time_to_do <= 0 ) {
3874 info.push_back( iteminfo( "DESCRIPTION",
3875 _( "It's done and <info>can be activated</info>." ) ) );
3876 } else {
3877 const std::string time = to_string_clipped( time_duration::from_turns( time_to_do ) );
3878 info.push_back( iteminfo( "DESCRIPTION",
3879 string_format( _( "It will be done in %s." ),
3880 time.c_str() ) ) );
3881 }
3882 }
3883 }
3884
3885 std::map<std::string, std::string>::const_iterator item_note = item_vars.find( "item_note" );
3886 std::map<std::string, std::string>::const_iterator item_note_tool =
3887 item_vars.find( "item_note_tool" );
3888
3889 if( item_note != item_vars.end() && parts->test( iteminfo_parts::DESCRIPTION_NOTES ) ) {
3891 std::string ntext;
3892 const inscribe_actor *use_actor = nullptr;
3893 if( item_note_tool != item_vars.end() ) {
3894 const use_function *use_func = itype_id( item_note_tool->second )->get_use( "inscribe" );
3895 use_actor = dynamic_cast<const inscribe_actor *>( use_func->get_actor_ptr() );
3896 }
3897 if( use_actor ) {
3898 //~ %1$s: gerund (e.g. carved), %2$s: item name, %3$s: inscription text
3899 ntext = string_format( pgettext( "carving", "%1$s on the %2$s is: %3$s" ),
3900 use_actor->gerund, tname(), item_note->second );
3901 } else {
3902 //~ %1$s: inscription text
3903 ntext = string_format( pgettext( "carving", "Note: %1$s" ), item_note->second );
3904 }
3905 info.push_back( iteminfo( "DESCRIPTION", ntext ) );
3906 }
3907
3908 if( this->get_var( "die_num_sides", 0 ) != 0 ) {
3909 info.emplace_back( "DESCRIPTION",
3910 string_format( _( "* This item can be used as a <info>die</info>, "
3911 "and has <info>%d</info> sides." ),
3912 static_cast<int>( this->get_var( "die_num_sides",
3913 0 ) ) ) );
3914 }
3915
3916 // Price and barter value
3917 const int price_preapoc = price( false ) * batch;
3918 const int price_postapoc = price( true ) * batch;
3919 if( parts->test( iteminfo_parts::BASE_PRICE ) ) {
3921 info.push_back( iteminfo( "BASE", _( "Price: " ), _( "$<num>" ),
3923 static_cast<double>( price_preapoc ) / 100 ) );
3924 }
3925 if( price_preapoc != price_postapoc && parts->test( iteminfo_parts::BASE_BARTER ) ) {
3926 info.push_back( iteminfo( "BASE", space + _( "Barter value: " ), _( "$<num>" ),
3928 static_cast<double>( price_postapoc ) / 100 ) );
3929 }
3930
3931 // Recipes using this item as an ingredient
3933 itype_id tid = contents.empty() ? typeId() : contents.front().typeId();
3934 const inventory &crafting_inv = you.crafting_inventory();
3935
3936 const recipe_subset available_recipe_subset = you.get_available_recipes( crafting_inv, nullptr,
3938 const std::set<const recipe *> &item_recipes = available_recipe_subset.of_component( tid );
3939
3940 if( item_recipes.empty() ) {
3942 info.push_back( iteminfo( "DESCRIPTION",
3943 _( "You know of nothing you could craft with it." ) ) );
3944 } else {
3945 if( item_recipes.size() > 24 ) {
3947 info.push_back( iteminfo( "DESCRIPTION",
3948 _( "You know dozens of things you could craft with it." ) ) );
3949 } else if( item_recipes.size() > 12 ) {
3951 info.push_back( iteminfo( "DESCRIPTION",
3952 _( "You could use it to craft various other things." ) ) );
3953 } else {
3954 // Extract item names from recipes and sort them
3955 std::vector<std::pair<std::string, bool>> result_names;
3957 item_recipes.begin(), item_recipes.end(),
3958 std::back_inserter( result_names ),
3959 [&crafting_inv]( const recipe * r ) {
3960 bool can_make = r->deduped_requirements().can_make_with_inventory(
3961 crafting_inv, r->get_component_filter() );
3962 return std::make_pair( r->result_name(), can_make );
3963 } );
3964 std::sort( result_names.begin(), result_names.end(), localized_compare );
3965 const std::string recipes =
3966 enumerate_as_string( result_names.begin(), result_names.end(),
3967 []( const std::pair<std::string, bool> &p ) {
3968 if( p.second ) {
3969 return p.first;
3970 } else {
3971 return string_format( "<dark>%s</dark>", p.first );
3972 }
3973 } );
3975 info.push_back( iteminfo( "DESCRIPTION",
3976 string_format( _( "You could use it to craft: %s" ),
3977 recipes ) ) );
3978 }
3979 }
3980 }
3981 if( get_option<bool>( "ENABLE_ASCII_ART_ITEM" ) ) {
3982 const ascii_art_id art = type->picture_id;
3983 if( art.is_valid() ) {
3984 for( const std::string &line : art->picture ) {
3985 info.push_back( iteminfo( "DESCRIPTION", line ) );
3986 }
3987 }
3988 }
3989}
static std::string to_string_clipped(const int num, const clipped_unit type, const clipped_align align)
Definition: calendar.cpp:228
const inventory & crafting_inventory(bool clear_path)
Definition: crafting.cpp:556
std::vector< std::string > picture
Definition: ascii_art.h:22
iterator begin() const
Definition: flat_set.h:83
iterator end() const
Definition: flat_set.h:86
This is a iuse_transform that uses the age of the item instead of a counter.
Definition: iuse_actor.h:289
int time_to_do(const item &it) const
How much longer (in turns) until the transformation can be done, can be negative.
Definition: iuse_actor.cpp:882
Writes on stuff (ground or items)
Definition: iuse_actor.h:610
translation gerund
Definition: iuse_actor.h:633
const FlagsSetType & get_flags() const
returs read-only set of flags of this item (not including flags from item type or gunmods)
Definition: item.cpp:5378
const std::vector< itype_id > & brewing_results() const
The results of fermenting this item.
Definition: item.cpp:5976
std::set< fault_id > faults
What faults (if any) currently apply to this item.
Definition: item.h:2164
time_duration brewing_time() const
Time for this item to be fully fermented.
Definition: item.cpp:5971
bool conductive() const
Whether the items is conductive.
Definition: item.cpp:6503
void bionic_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3295
int price(bool practical) const
Returns the monetary value of an item.
Definition: item.cpp:4946
void armor_fit_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2760
Definition: flag.h:15
std::string info() const
Get informative text for display in UI.
Definition: flag.h:30
recipe_subset get_available_recipes(const inventory &crafting_inv, const std::vector< npc * > *helpers=nullptr, recipe_filter filter=nullptr) const
Returns all available recipes (from books and npc companions)
Definition: player.cpp:297
const std::set< const recipe * > & of_component(const itype_id &id) const
Returns all recipes which could use component.
static const std::string flag_RADIOSIGNAL_2("RADIOSIGNAL_2")
static const std::string flag_FIRE_TWOHAND("FIRE_TWOHAND")
static const std::string flag_RADIOSIGNAL_1("RADIOSIGNAL_1")
static const std::string flag_DISABLE_SIGHTS("DISABLE_SIGHTS")
static const std::string flag_USE_UPS("USE_UPS")
static const std::string flag_RECHARGE("RECHARGE")
static const std::string flag_RADIO_ACTIVATION("RADIO_ACTIVATION")
static const std::string flag_RADIO_INVOKE_PROC("RADIO_INVOKE_PROC")
static const std::string flag_CONSUMABLE("CONSUMABLE")
static const std::string flag_NO_RELOAD("NO_RELOAD")
static const std::string flag_RADIOSIGNAL_3("RADIOSIGNAL_3")
static const std::string flag_LEAK_ALWAYS("LEAK_ALWAYS")
static const std::string flag_RADIO_MOD("RADIO_MOD")
std::unique_ptr< Item_factory > item_controller
@ DESCRIPTION_RECHARGE_UPSCAPABLE
@ DESCRIPTION_GUNMOD_DISABLESSIGHTS
@ DESCRIPTION_BREWABLE_DURATION
@ DESCRIPTION_RADIO_ACTIVATION_CHANNEL
@ DESCRIPTION_BREWABLE_PRODUCTS
@ DESCRIPTION_RECHARGE_NORELOAD
@ DESCRIPTION_ACTIVATABLE_TRANSFORMATION
@ DESCRIPTION_BIONIC_ARMOR_INTERFACE
@ DESCRIPTION_RADIOACTIVITY_DAMAGED
@ DESCRIPTION_RADIO_ACTIVATION_PROC
@ DESCRIPTION_RECHARGE_UPSMODDED
@ DESCRIPTION_GUNMOD_CONSUMABLE
@ DESCRIPTION_RADIOACTIVITY_ALWAYS
@ DESCRIPTION_RADIO_ACTIVATION
@ DESCRIPTION_APPLICABLE_RECIPES
void line(map *m, const ter_id &type, point p1, point p2)
Definition: mapgen.cpp:6281
void transform(player &p, const tripoint &pos)
Transform the examined object into the object specified by its transforms_into property.
Definition: iexamine.cpp:1642
recipe_filter recipe_filter_by_component(const itype_id &c)
ascii_art_id picture_id
Definition: itype.h:877
constexpr localized_comparator localized_compare
Definition: translations.h:342

References _, armor_fit_info(), BASE_BARTER, BASE_PRICE, BASE_RIGIDITY, cata::flat_set< T, Compare, Data >::begin(), bionic_info(), brewing_results(), brewing_time(), itype::can_use(), charges, conductive(), contents, Character::crafting_inventory(), damage(), debug, DESCRIPTION_ACTIVATABLE_TRANSFORMATION, DESCRIPTION_APPLICABLE_RECIPES, DESCRIPTION_BIONIC_ARMOR_INTERFACE, DESCRIPTION_BREWABLE_DURATION, DESCRIPTION_BREWABLE_PRODUCTS, DESCRIPTION_CONDUCTIVITY, DESCRIPTION_FAULTS, DESCRIPTION_FLAGS, DESCRIPTION_GUNMOD_CONSUMABLE, DESCRIPTION_GUNMOD_DISABLESSIGHTS, DESCRIPTION_HOLSTERS, DESCRIPTION_NOTES, DESCRIPTION_RADIO_ACTIVATION, DESCRIPTION_RADIO_ACTIVATION_CHANNEL, DESCRIPTION_RADIO_ACTIVATION_PROC, DESCRIPTION_RADIOACTIVITY_ALWAYS, DESCRIPTION_RADIOACTIVITY_DAMAGED, DESCRIPTION_RECHARGE_NORELOAD, DESCRIPTION_RECHARGE_UPSCAPABLE, DESCRIPTION_RECHARGE_UPSMODDED, DESCRIPTION_TWOHANDED, item_contents::empty(), cata::flat_set< T, Compare, Data >::end(), enumerate_as_string(), faults, flag_CONDUCTIVE(), flag_CONSUMABLE(), flag_DISABLE_SIGHTS(), flag_FIRE_TWOHAND(), flag_LEAK_ALWAYS(), flag_LEAK_DAM(), flag_NO_RELOAD(), flag_RADIO_ACTIVATION(), flag_RADIO_INVOKE_PROC(), flag_RADIO_MOD(), flag_RADIOACTIVE(), flag_RADIOSIGNAL_1(), flag_RADIOSIGNAL_2(), flag_RADIOSIGNAL_3(), flag_RECHARGE(), flag_USE_UPS(), flag_USES_BIONIC_POWER(), time_duration::from_turns(), item_contents::front(), inscribe_actor::gerund, json_flag::get(), use_function::get_actor_ptr(), player::get_available_recipes(), get_avatar(), get_flags(), itype::get_flags(), itype::get_use(), get_var(), has_flag(), has_own_flag(), Character::has_trait(), json_flag::info(), info(), insert_separation_line(), is_armor(), is_brewable(), iteminfo::is_decimal, is_gun(), is_gunmod(), is_null(), is_power_armor(), is_tool(), item_controller, item_vars, itype_id, localized_compare, iteminfo::lower_is_better, made_of(), nname(), iteminfo::no_newline, recipe_subset::of_component(), pgettext(), price(), ptr(), recipe_filter_by_component(), itype::rigid, sign::space, string_format(), iteminfo_query::test(), time, delayed_transform_iuse::time_to_do(), tname(), to_string_clipped(), trait_WOOLALLERGY, iexamine::transform(), type, typeId(), itype::use_methods, and vgettext().

Referenced by info().

◆ find_armor_data()

const islot_armor * item::find_armor_data ( ) const

If this is an armor item, return its armor data.

You should probably not use this function, use the various functions above (like get_storage) to access armor data directly.

Definition at line 6707 of file item.cpp.

6708{
6709 if( type->armor ) {
6710 return &*type->armor;
6711 }
6712 // Currently the only way to make a non-armor item into armor is to install a gun mod.
6713 // The gunmods are stored in the items contents, as are the contents of a container, and the
6714 // tools in a tool belt (a container actually), or the ammo in a quiver (container again).
6715 for( const item *mod : gunmods() ) {
6716 if( mod->type->armor ) {
6717 return &*mod->type->armor;
6718 }
6719 }
6720 return nullptr;
6721}
cata::value_ptr< islot_armor > armor
Definition: itype.h:820

References itype::armor, gunmods(), and type.

Referenced by get_base_env_resist(), get_base_env_resist_w_filter(), get_coverage(), get_covered_body_parts(), get_encumber(), get_encumber_when_containing(), get_env_resist(), get_storage(), get_thickness(), get_warmth(), get_weight_capacity_bonus(), get_weight_capacity_modifier(), is_armor(), and is_sided().

◆ fire_resist()

int item::fire_resist ( bool  to_self = false,
int  base_env_resist = 0 
) const

Definition at line 6186 of file item.cpp.

6187{
6188 if( to_self ) {
6189 // Fire damages items in a different way
6190 return INT_MAX;
6191 }
6192
6193 float resist = 0.0;
6195 if( is_null() ) {
6196 return 0.0;
6197 }
6198
6199 const std::vector<const material_type *> mat_types = made_of_types();
6200 if( !mat_types.empty() ) {
6201 for( const material_type *mat : mat_types ) {
6202 resist += mat->fire_resist();
6203 }
6204 // Average based on number of materials.
6205 resist /= mat_types.size();
6206 }
6207
6208 const int env = get_env_resist( base_env_resist );
6209 if( env < 10 ) {
6210 // Iron resists immersion in magma, iron-clad knight won't.
6211 resist *= env / 10.0f;
6212 }
6213
6214 return std::lround( resist + mod );
6215}
@ clothing_mod_type_fire
Definition: clothing_mod.h:18

References clothing_mod_type_fire, get_clothing_mod_val(), get_env_resist(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), and sew_advanced_actor::use().

◆ flammable()

bool item::flammable ( int  threshold = 0) const

Whether the items is flammable.

(Make sure to keep this in sync with fire code in fields.cpp)

Parameters
thresholdItem is flammable if it provides more fuel than threshold.

Definition at line 8337 of file item.cpp.

8338{
8339 const std::vector<const material_type *> &mats = made_of_types();
8340 if( mats.empty() ) {
8341 // Don't know how to burn down something made of nothing.
8342 return false;
8343 }
8344
8345 int flammability = 0;
8346 units::volume volume_per_turn = 0_ml;
8347 for( const material_type *m : mats ) {
8348 const mat_burn_data &bd = m->burn_data( 1 );
8349 if( bd.immune ) {
8350 // Made to protect from fire
8351 return false;
8352 }
8353
8354 flammability += bd.fuel;
8355 volume_per_turn += bd.volume_per_turn;
8356 }
8357
8358 if( threshold == 0 || flammability <= 0 ) {
8359 return flammability > 0;
8360 }
8361
8362 volume_per_turn /= mats.size();
8363 units::volume vol = base_volume();
8364 if( volume_per_turn > 0_ml && volume_per_turn < vol ) {
8365 flammability = flammability * volume_per_turn / vol;
8366 } else {
8367 // If it burns well, it provides a bonus here
8368 flammability *= vol / units::legacy_volume_factor;
8369 }
8370
8371 return flammability > threshold;
8372}
Contains burning parameters for a given material.
Definition: fire.h:46
bool immune
If this is true, an object will not burn or be destroyed by fire.
Definition: fire.h:48
units::volume volume_per_turn
If non-zero and lower than item's volume, scale burning by volume_penalty / volume.
Definition: fire.h:50
float fuel
Fuel contributed per tick when this material burns.
Definition: fire.h:52

References base_volume(), mat_burn_data::fuel, mat_burn_data::immune, units::legacy_volume_factor, made_of_types(), and mat_burn_data::volume_per_turn.

Referenced by Character::can_feed_furnace_with(), behavior::character_oracle_t::can_make_fire(), and monster::process_turn().

◆ food_info()

void item::food_info ( const item food_item,
std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug,
temperature_flag  temperature 
) const
Survival >=3 allows detection of poisonous food Survival >=5 allows detection of hallucinogenic food

Definition at line 1673 of file item.cpp.

1676{
1677 nutrients min_nutr;
1678 nutrients max_nutr;
1679 avatar &you = get_avatar();
1680
1681 std::string recipe_exemplar = get_var( "recipe_exemplar", "" );
1682 if( recipe_exemplar.empty() ) {
1683 min_nutr = max_nutr = you.compute_effective_nutrients( *food_item );
1684 } else {
1685 std::tie( min_nutr, max_nutr ) =
1686 you.compute_nutrient_range( *food_item, recipe_id( recipe_exemplar ) );
1687 }
1688
1689 bool show_nutr = parts->test( iteminfo_parts::FOOD_NUTRITION ) ||
1691 if( min_nutr != max_nutr && show_nutr ) {
1692 info.emplace_back(
1693 "FOOD", _( "Nutrition will <color_cyan>vary with chosen ingredients</color>." ) );
1694 if( recipe_dict.is_item_on_loop( food_item->typeId() ) ) {
1695 info.emplace_back(
1696 "FOOD", _( "Nutrition range cannot be calculated accurately due to "
1697 "<color_red>recipe loops</color>." ) );
1698 }
1699 }
1700
1701 const std::string space = " ";
1702 if( max_nutr.kcal != 0 || food_item->get_comestible()->quench != 0 ) {
1703 if( parts->test( iteminfo_parts::FOOD_NUTRITION ) ) {
1704 info.push_back( iteminfo( "FOOD", _( "<bold>Calories (kcal)</bold>: " ),
1705 "", iteminfo::no_newline, min_nutr.kcal ) );
1706 if( max_nutr.kcal != min_nutr.kcal ) {
1707 info.push_back( iteminfo( "FOOD", _( "-" ),
1708 "", iteminfo::no_newline, max_nutr.kcal ) );
1709 }
1710 }
1711 if( parts->test( iteminfo_parts::FOOD_QUENCH ) ) {
1712 info.push_back( iteminfo( "FOOD", space + _( "Quench: " ),
1713 food_item->get_comestible()->quench ) );
1714 }
1715 }
1716
1717 const std::pair<int, int> fun_for_food_item = you.fun_for( *food_item );
1718 if( fun_for_food_item.first != 0 && parts->test( iteminfo_parts::FOOD_JOY ) ) {
1719 info.push_back( iteminfo( "FOOD", _( "Enjoyability: " ), fun_for_food_item.first ) );
1720 }
1721
1722 if( parts->test( iteminfo_parts::FOOD_PORTIONS ) ) {
1723 info.push_back( iteminfo( "FOOD", _( "Portions: " ),
1724 std::abs( static_cast<int>( food_item->charges ) * batch ) ) );
1725 }
1726 if( food_item->corpse != nullptr && parts->test( iteminfo_parts::FOOD_SMELL ) &&
1727 ( debug || ( g != nullptr && ( you.has_trait( trait_CARNIVORE ) ||
1729 info.push_back( iteminfo( "FOOD", _( "Smells like: " ) + food_item->corpse->nname() ) );
1730 }
1731
1732 auto format_vitamin = [&]( const std::pair<vitamin_id, int> &v, bool display_vitamins ) {
1733 const bool is_vitamin = v.first->type() == vitamin_type::VITAMIN;
1734 // only display vitamins that we actually require
1735 if( you.vitamin_rate( v.first ) == 0_turns || v.second == 0 ||
1736 display_vitamins != is_vitamin || v.first->has_flag( flag_NO_DISPLAY ) ) {
1737 return std::string();
1738 }
1739 const double multiplier = you.vitamin_rate( v.first ) / 1_days * 100;
1740 const int min_value = min_nutr.get_vitamin( v.first );
1741 const int max_value = v.second;
1742 const int min_rda = std::lround( min_value * multiplier );
1743 const int max_rda = std::lround( max_value * multiplier );
1744 const std::string format = min_rda == max_rda ? "%s (%i%%)" : "%s (%i-%i%%)";
1745 return string_format( format, v.first->name(), min_value, max_value );
1746 };
1747
1748 const auto max_nutr_vitamins = sorted_lex( max_nutr.vitamins );
1749 const std::string required_vits = enumerate_as_string(
1750 max_nutr_vitamins.begin(),
1751 max_nutr_vitamins.end(),
1752 [&]( const std::pair<vitamin_id, int> &v ) {
1753 return format_vitamin( v, true );
1754 } );
1755
1756 const std::string effect_vits = enumerate_as_string(
1757 max_nutr_vitamins.begin(),
1758 max_nutr_vitamins.end(),
1759 [&]( const std::pair<vitamin_id, int> &v ) {
1760 return format_vitamin( v, false );
1761 } );
1762
1763 if( !required_vits.empty() && parts->test( iteminfo_parts::FOOD_VITAMINS ) ) {
1764 info.emplace_back( "FOOD", _( "Vitamins (RDA): " ), required_vits );
1765 }
1766
1767 if( !effect_vits.empty() && parts->test( iteminfo_parts::FOOD_VIT_EFFECTS ) ) {
1768 info.emplace_back( "FOOD", _( "Other contents: " ), effect_vits );
1769 }
1770
1772
1773 if( you.allergy_type( *food_item ) != morale_type( "morale_null" ) ) {
1774 info.emplace_back( "DESCRIPTION",
1775 _( "* This food will cause an <bad>allergic reaction</bad>." ) );
1776 }
1777
1778 if( food_item->has_flag( flag_CANNIBALISM ) &&
1780 if( !you.has_trait_flag( trait_flag_CANNIBAL ) ) {
1781 info.emplace_back( "DESCRIPTION",
1782 _( "* This food contains <bad>human flesh</bad>." ) );
1783 } else {
1784 info.emplace_back( "DESCRIPTION",
1785 _( "* This food contains <good>human flesh</good>." ) );
1786 }
1787 }
1788
1789 if( food_item->is_tainted() && parts->test( iteminfo_parts::FOOD_CANNIBALISM ) ) {
1790 info.emplace_back( "DESCRIPTION",
1791 _( "* This food is <bad>tainted</bad> and will poison you." ) );
1792 }
1793
1794 ///\EFFECT_SURVIVAL >=3 allows detection of poisonous food
1795 if( food_item->has_flag( flag_HIDDEN_POISON ) && you.get_skill_level( skill_survival ) >= 3 &&
1796 parts->test( iteminfo_parts::FOOD_POISON ) ) {
1797 info.emplace_back( "DESCRIPTION",
1798 _( "* On closer inspection, this appears to be "
1799 "<bad>poisonous</bad>." ) );
1800 }
1801
1802 ///\EFFECT_SURVIVAL >=5 allows detection of hallucinogenic food
1803 if( food_item->has_flag( flag_HIDDEN_HALLU ) && you.get_skill_level( skill_survival ) >= 5 &&
1805 info.emplace_back( "DESCRIPTION",
1806 _( "* On closer inspection, this appears to be "
1807 "<neutral>hallucinogenic</neutral>." ) );
1808 }
1809
1810 if( food_item->goes_bad() && parts->test( iteminfo_parts::FOOD_ROT ) ) {
1811 const std::string rot_time = to_string_clipped( food_item->get_shelf_life() );
1812 info.emplace_back( "DESCRIPTION",
1813 string_format( _( "* This food is <neutral>perishable</neutral>, "
1814 "and at room temperature has an estimated nominal "
1815 "shelf life of <info>%s</info>." ), rot_time ) );
1816
1817
1818 if( parts->test( iteminfo_parts::FOOD_ROT_STORAGE ) ) {
1819 const char *temperature_description;
1820 bool print_freshness_duration = false;
1821 // There should be a better way to do this...
1822 switch( temperature ) {
1825 temperature_description = _( "* Current storage conditions <bad>do not</bad> "
1826 "protect this item from rot." );
1827 }
1828 break;
1831 temperature_description = _( "* Current storage conditions <neutral>partially</neutral> "
1832 "protect this item from rot. It will stay fresh at least <info>%s</info>." );
1833 print_freshness_duration = true;
1834 }
1835 break;
1837 temperature_description = _( "* Current storage conditions <good>fully</good> "
1838 "protect this item from rot. It will stay fresh indefinitely." );
1839 }
1840 break;
1841 default: {
1842 temperature_description = "BUGGED TEMPERATURE INFO";
1843 }
1844 }
1845
1846 if( print_freshness_duration ) {
1847 time_duration remaining_fresh = food_item->minimum_freshness_duration( temperature );
1848 std::string time_string = to_string_clipped( remaining_fresh );
1849 info.emplace_back( "DESCRIPTION", string_format( temperature_description, time_string ) );
1850 } else {
1851 info.emplace_back( "DESCRIPTION", temperature_description );
1852 }
1853 }
1854
1855 if( !food_item->rotten() ) {
1856 info.emplace_back( "DESCRIPTION", get_freshness_description( *food_item ) );
1857 }
1858
1859 if( food_item->has_flag( flag_NO_PARASITES ) ) {
1860 info.emplace_back( "DESCRIPTION",
1861 _( "* It seems that deep freezing <good>killed all "
1862 "parasites</good>." ) );
1863 }
1864 if( food_item->rotten() ) {
1865 if( you.has_bionic( bio_digestion ) ) {
1866 info.push_back( iteminfo( "DESCRIPTION",
1867 _( "This food has started to <neutral>rot</neutral>, "
1868 "but <info>your bionic digestion can tolerate "
1869 "it</info>." ) ) );
1870 } else if( you.has_trait( trait_SAPROVORE ) ) {
1871 info.push_back( iteminfo( "DESCRIPTION",
1872 _( "This food has started to <neutral>rot</neutral>, "
1873 "but <info>you can tolerate it</info>." ) ) );
1874 } else {
1875 info.push_back( iteminfo( "DESCRIPTION",
1876 _( "This food has started to <bad>rot</bad>. "
1877 "<info>Eating</info> it would be a <bad>very bad "
1878 "idea</bad>." ) ) );
1879 }
1880 }
1881 }
1882}
bool has_trait_flag(const std::string &b) const
Returns true if player has a trait with a flag.
Definition: mutation.cpp:106
virtual bool has_artifact_with(art_effect_passive effect) const
Definition: character.cpp:3210
nutrients compute_effective_nutrients(const item &) const
std::pair< nutrients, nutrients > compute_nutrient_range(const item &, const recipe_id &, const cata::flat_set< std::string > &extra_flags={}) const
Get calorie & vitamin contents for a comestible, taking into account character traits.
time_duration vitamin_rate(const vitamin_id &vit) const
Get vitamin usage rate (minutes per unit) accounting for bionics, mutations and effects.
std::pair< int, int > fun_for(const item &comest) const
Handles the enjoyability value for a comestible.
bool rotten() const
returns true if item is now rotten after all shelf life has elapsed
Definition: item.h:849
time_duration minimum_freshness_duration(temperature_flag temperature) const
Time that this item is guaranteed to stay fresh.
Definition: item.cpp:5725
const cata::value_ptr< islot_comestible > & get_comestible() const
Definition: item.cpp:10153
bool is_tainted() const
Is item derived from a zombie?
Definition: item.cpp:9846
bool is_item_on_loop(const itype_id &) const
@ AEP_SUPER_CLAIRVOYANCE
Definition: enums.h:112
static const std::string flag_HIDDEN_POISON("HIDDEN_POISON")
static const std::string flag_NO_DISPLAY("NO_DISPLAY")
static const bionic_id bio_digestion("bio_digestion")
static const trait_id trait_CARNIVORE("CARNIVORE")
static const std::string flag_CANNIBALISM("CANNIBALISM")
static const std::string flag_HIDDEN_HALLU("HIDDEN_HALLU")
static const trait_id trait_SAPROVORE("SAPROVORE")
static const std::string flag_NO_PARASITES("NO_PARASITES")
static const std::string trait_flag_CANNIBAL("CANNIBAL")
static const skill_id skill_survival("survival")
static std::string get_freshness_description(const item &food_item)
Definition: item.cpp:1114
constexpr T max_value()
recipe_dictionary recipe_dict
int kcal
amount of kcal this food has
Definition: stomach.h:18
std::map< vitamin_id, int > vitamins
vitamins potentially provided by this comestible (if any)
Definition: stomach.h:21
int get_vitamin(const vitamin_id &) const
Definition: stomach.cpp:42
string_id< recipe > recipe_id
Definition: type_id.h:143
@ VITAMIN
Definition: vitamin.h:19

References _, AEP_SUPER_CLAIRVOYANCE, Character::allergy_type(), bio_digestion, charges, Character::compute_effective_nutrients(), Character::compute_nutrient_range(), corpse, debug, enumerate_as_string(), flag_CANNIBALISM(), flag_HIDDEN_HALLU(), flag_HIDDEN_POISON(), flag_NO_DISPLAY(), flag_NO_PARASITES(), FOOD_CANNIBALISM, FOOD_HALLUCINOGENIC, FOOD_JOY, FOOD_NUTRITION, FOOD_POISON, FOOD_PORTIONS, FOOD_QUENCH, FOOD_ROT, FOOD_ROT_STORAGE, FOOD_SMELL, FOOD_VIT_EFFECTS, FOOD_VITAMINS, format(), Character::fun_for(), g, get_avatar(), get_comestible(), get_freshness_description(), get_shelf_life(), Character::get_skill_level(), get_var(), nutrients::get_vitamin(), goes_bad(), Character::has_artifact_with(), Character::has_bionic(), has_flag(), Character::has_trait(), Character::has_trait_flag(), info(), insert_separation_line(), recipe_dictionary::is_item_on_loop(), is_tainted(), nutrients::kcal, detail::max_value(), minimum_freshness_duration(), mtype::nname(), iteminfo::no_newline, recipe_dict, rotten(), skill_survival, sorted_lex(), sign::space, string_format(), TEMP_FREEZER, TEMP_FRIDGE, TEMP_HEATER, TEMP_NORMAL, TEMP_ROOT_CELLAR, iteminfo_query::test(), to_string_clipped(), trait_CARNIVORE, trait_flag_CANNIBAL(), trait_SAPROVORE, typeId(), VITAMIN, Character::vitamin_rate(), and nutrients::vitamins.

Referenced by info().

◆ fuel_energy()

float item::fuel_energy ( ) const

Returns energy of one charge of this item as fuel for an engine.

Definition at line 6841 of file item.cpp.

6842{
6843 return is_fuel() ? type->fuel->energy : 0.0f;
6844}
bool is_fuel() const
Definition: item.cpp:6785
cata::value_ptr< islot_fuel > fuel
Definition: itype.h:826

References itype::fuel, is_fuel(), and type.

Referenced by Character::burn_fuel(), vehicle_part::consume_energy(), vehicle::consume_fuel(), vehicle::consumption_per_hour(), Character::get_acquirable_energy(), game::on_move_effects(), and Character::passive_power_gen().

◆ fuel_pump_terrain()

std::string item::fuel_pump_terrain ( ) const

Returns the string of the id of the terrain that pumps this fuel, if any.

Definition at line 6846 of file item.cpp.

6847{
6848 return is_fuel() ? type->fuel->pump_terrain : "t_null";
6849}

References itype::fuel, is_fuel(), and type.

Referenced by map::place_gas_pump().

◆ get_available_recipes()

std::vector< std::pair< const recipe *, int > > item::get_available_recipes ( const player u) const

Enumerates recipes available from this book and the skill level required to use them.

Definition at line 7140 of file item.cpp.

7141{
7142 std::vector<std::pair<const recipe *, int>> recipe_entries;
7143 if( is_book() ) {
7144 for( const islot_book::recipe_with_description_t &elem : type->book->recipes ) {
7145 if( u.get_skill_level( elem.recipe->skill_used ) >= elem.skill_level ) {
7146 recipe_entries.push_back( std::make_pair( elem.recipe, elem.skill_level ) );
7147 }
7148 }
7149 } else if( has_var( "EIPC_RECIPES" ) ) {
7150 // See einkpc_download_memory_card() in iuse.cpp where this is set.
7151 const std::string recipes = get_var( "EIPC_RECIPES" );
7152 // Capture the index one past the delimiter, i.e. start of target string.
7153 size_t first_string_index = recipes.find_first_of( ',' ) + 1;
7154 while( first_string_index != std::string::npos ) {
7155 size_t next_string_index = recipes.find_first_of( ',', first_string_index );
7156 if( next_string_index == std::string::npos ) {
7157 break;
7158 }
7159 std::string new_recipe = recipes.substr( first_string_index,
7160 next_string_index - first_string_index );
7161 const recipe *r = &recipe_id( new_recipe ).obj();
7162 if( u.get_skill_level( r->skill_used ) >= r->difficulty ) {
7163 recipe_entries.push_back( std::make_pair( r, r->difficulty ) );
7164 }
7165 first_string_index = next_string_index + 1;
7166 }
7167 }
7168 return recipe_entries;
7169}
int difficulty
Definition: recipe.h:62

References itype::book, recipe::difficulty, Character::get_skill_level(), get_var(), has_var(), is_book(), string_id< T >::obj(), islot_book::recipe_with_description_t::recipe, islot_book::recipe_with_description_t::skill_level, recipe::skill_used, and type.

Referenced by avatar::do_read(), and player::get_recipes_from_books().

◆ get_base_env_resist_w_filter()

int item::get_base_env_resist_w_filter ( ) const

Returns the base resistance to environmental effects if an item (for example a gas mask) requires a gas filter to operate and this filter is installed.

Used in iuse::gasmask to change protection of a gas mask if it has (or don't has) filters. For other applications use get_env_resist() above.

Definition at line 5802 of file item.cpp.

5803{
5804 const islot_armor *t = find_armor_data();
5805 if( t == nullptr ) {
5806 return is_pet_armor() ? type->pet_armor->env_resist_w_filter : 0;
5807 }
5808 return t->env_resist_w_filter;
5809}
const islot_armor * find_armor_data() const
If this is an armor item, return its armor data.
Definition: item.cpp:6707
int env_resist_w_filter
Environmental protection of a gas mask with installed filter.
Definition: itype.h:267
cata::value_ptr< islot_pet_armor > pet_armor
Definition: itype.h:821

References islot_armor::env_resist_w_filter, find_armor_data(), is_pet_armor(), itype::pet_armor, and type.

Referenced by armor_protection_info(), iuse::dive_tank(), and iuse::gasmask().

◆ get_base_material()

const material_type & item::get_base_material ( ) const

Get the basic (main) material of this item.

May return the null-material.

Definition at line 7176 of file item.cpp.

7177{
7178 const std::vector<material_id> &mats = made_of();
7179 return mats.empty() ? material_id::NULL_ID().obj() : mats.front().obj();
7180}

References made_of(), string_id< material_type >::NULL_ID(), and string_id< T >::obj().

Referenced by Character::armor_absorb(), and durability_indicator().

◆ get_cable_target()

std::optional< tripoint > item::get_cable_target ( Character p,
const tripoint pos 
) const

Gets the point (vehicle tile) the cable is connected to.

Returns nothing if not connected to anything.

Definition at line 9371 of file item.cpp.

9372{
9373 const std::string &state = get_var( "state" );
9374 if( state != "pay_out_cable" && state != "cable_charger_link" ) {
9375 return std::nullopt;
9376 }
9377 map &here = get_map();
9378 const optional_vpart_position vp_pos = here.veh_at( pos );
9379 if( vp_pos ) {
9380 const std::optional<vpart_reference> seat = vp_pos.part_with_feature( "BOARDABLE", true );
9381 if( seat && p == seat->vehicle().get_passenger( seat->part_index() ) ) {
9382 return pos;
9383 }
9384 }
9385
9386 tripoint source( get_var( "source_x", 0 ), get_var( "source_y", 0 ), get_var( "source_z", 0 ) );
9387
9388 return here.getlocal( source );
9389}
Manage and cache data about a part of the map.
Definition: map.h:384
tripoint getlocal(const tripoint &p) const
Inverse of getabs.
Definition: map.cpp:8409
optional_vpart_position veh_at(const tripoint &p) const
Checks if tile is occupied by vehicle and by which part.
Definition: map.cpp:1073
Simple wrapper to forward functions that may return a std::optional to vpart_position.
std::optional< vpart_reference > part_with_feature(const std::string &f, bool unbroken) const
Definition: vehicle.cpp:2482

References get_map(), get_var(), map::getlocal(), optional_vpart_position::part_with_feature(), and map::veh_at().

Referenced by process_cable().

◆ get_cached_tool_selections()

const std::vector< comp_selection< tool_comp > > & item::get_cached_tool_selections ( ) const

Definition at line 10147 of file item.cpp.

10148{
10149 assert( craft_data_ );
10150 return craft_data_->cached_tool_selections;
10151}

References craft_data_.

◆ get_category()

const item_category & item::get_category ( ) const

Definition at line 8707 of file item.cpp.

8708{
8709 if( is_container() && !contents.empty() ) {
8710 return contents.front().get_category();
8711 }
8712
8713 static item_category null_category;
8714 return type->category_force.is_valid() ? type->category_force.obj() : null_category;
8715}
Contains metadata for one category of items.
Definition: item_category.h:35
item_category_id category_force
If set via JSON forces item category to this (preventing automatic assignment)
Definition: itype.h:971

References itype::category_force, contents, item_contents::empty(), item_contents::front(), get_category(), is_container(), string_id< T >::is_valid(), string_id< T >::obj(), and type.

Referenced by inventory_selector::add_items(), basic_info(), json_talk_topic::gen_responses(), get_category(), inventory_entry::get_category_ptr(), zone_manager::get_near_zone_type_for_item(), is_map(), map_item_stack::map_item_stack_sort(), operator<(), conditional_t< T >::set_has_item_category(), and spoilage_sort_order().

◆ get_chapters()

int item::get_chapters ( ) const

How many chapters the book has (if any).

Will be 0 if the item is not a book, or if it has no chapters at all. Each reading will "consume" a chapter, if the book has no unread chapters, it's less fun.

Definition at line 7114 of file item.cpp.

7115{
7116 if( !type->book ) {
7117 return 0;
7118 }
7119 return type->book->chapters;
7120}

References itype::book, and type.

Referenced by display_name(), character_funcs::get_book_fun_for(), get_remaining_chapters(), and io().

◆ get_clothing_mod_val()

float item::get_clothing_mod_val ( clothing_mod_type  type) const

Definition at line 10172 of file item.cpp.

10173{
10175 type );
10176 return get_var( key, 0.0 );
10177}
static const std::string CLOTHING_MOD_VAR_PREFIX("clothing_mod_")
std::string string_from_clothing_mod_type(clothing_mod_type type)

References CLOTHING_MOD_VAR_PREFIX(), get_var(), clothing_mods::string_from_clothing_mod_type(), and type.

Referenced by acid_resist(), bash_resist(), bullet_resist(), cut_resist(), fire_resist(), get_encumber_when_containing(), get_storage(), and get_warmth().

◆ get_comestible()

◆ get_comestible_fun()

int item::get_comestible_fun ( ) const

Definition at line 5507 of file item.cpp.

5508{
5509 if( !is_comestible() ) {
5510 return 0;
5511 }
5512 int fun = get_comestible()->fun;
5513 for( const std::string &flag : item_tags ) {
5514 fun += json_flag::get( flag ).taste_mod();
5515 }
5516 for( const std::string &flag : type->get_flags() ) {
5517 fun += json_flag::get( flag ).taste_mod();
5518 }
5519
5520 return fun;
5521}
bool is_comestible() const
Definition: item.cpp:6612
int taste_mod() const
The flag's modifier on the fun value of comestibles.
Definition: flag.h:55

References json_flag::get(), get_comestible(), itype::get_flags(), is_comestible(), item_tags, json_flag::taste_mod(), and type.

Referenced by iuse::blech(), basecamp::distribute_food(), mattack::eat_food(), Character::fun_for(), med_info(), rate_food(), and npc::will_accept_from_player().

◆ get_contained()

const item & item::get_contained ( ) const

Return a contained item (if any and only one).

Definition at line 7076 of file item.cpp.

7077{
7078 if( contents.empty() ) {
7079 return null_item_reference();
7080 }
7081 return contents.front();
7082}
item & null_item_reference()
Returns a reference to a null item (see item::is_null).
Definition: item.cpp:325

References contents, item_contents::empty(), item_contents::front(), and null_item_reference().

Referenced by Character::consume_effects(), basecamp::distribute_food(), trading_window::get_var_trade(), Character::invoke_item(), examine_item_menu::rate_action_use(), ranged::throw_item(), try_consume(), avatar_funcs::use_item(), avatar::wield(), avatar_action::wield(), npc::wield_better_weapon(), and npc::will_accept_from_player().

◆ get_container_capacity()

units::volume item::get_container_capacity ( ) const

It returns the total capacity (volume) of the container for liquids.

Definition at line 8417 of file item.cpp.

8418{
8419 if( !is_container() ) {
8420 return 0_ml;
8421 }
8422 return type->container->contains;
8423}

References itype::container, is_container(), and type.

Referenced by vehicle_part::ammo_capacity(), display_name(), get_remaining_capacity_for_liquid(), get_total_capacity(), is_funnel_container(), Item_factory::migrate_item(), Item_modifier::modify(), and ranged::throw_item().

◆ get_continue_reqs()

requirement_data item::get_continue_reqs ( ) const

Returns requirement data representing what is needed to resume work on an in progress craft.

Causes a debugmsg and returns empty requirement data if called on a non-craft

Returns
what is needed to continue craft, may be empty requirement data

Definition at line 975 of file crafting.cpp.

976{
977 if( !is_craft() ) {
978 debugmsg( "get_continue_reqs() called on non-craft '%s.' Aborting.", tname() );
979 return requirement_data();
980 }
982}
static requirement_data continue_requirements(const std::vector< item_comp > &required_comps, const std::list< item > &remaining_comps)
Returns the item requirements to continue an in progress craft with the passed components.

References components, requirement_data::continue_requirements(), craft_data_, debugmsg, is_craft(), and tname().

◆ get_corpse_name()

std::string item::get_corpse_name ( )

Returns name of deceased being if it had any or empty string if not.

Definition at line 9943 of file item.cpp.

9944{
9945 if( corpse_name.empty() ) {
9946 return std::string();
9947 }
9948 return corpse_name;
9949}
std::string corpse_name
Definition: item.h:2173

References corpse_name.

◆ get_coverage()

int item::get_coverage ( ) const

Returns the relative coverage that this item has when worn.

Values range from 0 (not covering anything, or no armor at all) to 100 (covering the whole body part). Items that cover more are more likely to absorb damage from attacks.

Definition at line 5925 of file item.cpp.

5926{
5927 const islot_armor *t = find_armor_data();
5928 if( t == nullptr ) {
5929 return 0;
5930 }
5931 return t->coverage;
5932}
int coverage
Percentage of the body part area that this item covers.
Definition: itype.h:255

References islot_armor::coverage, and find_armor_data().

Referenced by Character::armor_absorb(), armor_info(), armor_inventory_preset::armor_inventory_preset(), Character::block_ranged_hit(), relic_funcs::check_recharge_reqs(), anonymous_namespace{armor_layers.cpp}::clothing_properties(), clothing_mod::get_mod_val(), character_funcs::is_bp_immune_to(), map::player_in_field(), tutorial_game::post_action(), wind_resistance_from_item_list(), and mdefense::zapback().

◆ get_covered_body_parts() [1/2]

body_part_set item::get_covered_body_parts ( ) const

Bitset of all covered body parts.

If the bit is set, the body part is covered by this item (when worn). The index of the bit should be a body part, for example:

if( some_armor.get_covered_body_parts().test( bp_head ) ) { ... }

For testing only a single body part, use covers instead. This function allows you to get the whole covering data in one call.

Definition at line 756 of file item.cpp.

757{
759}

References get_covered_body_parts(), and get_side().

Referenced by npc::adjust_worn(), Character::armor_absorb(), armor_info(), Character::can_swap(), Character::can_wear(), covers(), get_covered_body_parts(), layer_item(), on_wear(), player_morale::on_worn_item_washed(), player_morale::set_worn(), and weather_effect::wet_player().

◆ get_covered_body_parts() [2/2]

body_part_set item::get_covered_body_parts ( side  s) const

Bitset of all covered body parts, from a specific side.

If the bit is set, the body part is covered by this item (when worn). The index of the bit should be a body part, for example:

if( some_armor.get_covered_body_parts().test( bp_head ) ) { ... }

For testing only a single body part, use covers instead. This function allows you to get the whole covering data in one call.

Parameters
sSpecifies the side. Will be ignored for non-sided items.

Definition at line 761 of file item.cpp.

762{
763 body_part_set res;
764
765 if( is_gun() ) {
766 // Currently only used for guns with the should strap mod, other guns might
767 // go on another bodypart.
768 res.set( bp_torso );
769 }
770
771 const islot_armor *armor = find_armor_data();
772 if( armor == nullptr ) {
773 return res;
774 }
775
776 res |= armor->covers;
777
778 if( !armor->sided ) {
779 return res; // Just ignore the side.
780 }
781
782 switch( s ) {
783 case side::BOTH:
784 case side::num_sides:
785 break;
786
787 case side::LEFT:
788 res.reset( bp_arm_r );
789 res.reset( bp_hand_r );
790 res.reset( bp_leg_r );
791 res.reset( bp_foot_r );
792 break;
793
794 case side::RIGHT:
795 res.reset( bp_arm_l );
796 res.reset( bp_hand_l );
797 res.reset( bp_leg_l );
798 res.reset( bp_foot_l );
799 break;
800 }
801
802 return res;
803}
void set(const body_part &bp)
Definition: bodypart.h:253
void reset()
Definition: bodypart.h:256
bool sided
Whether this item can be worn on either side of the body.
Definition: itype.h:242
body_part_set covers
Bitfield of enum body_part TODO: document me.
Definition: itype.h:238

References BOTH, bp_arm_l, bp_arm_r, bp_foot_l, bp_foot_r, bp_hand_l, bp_hand_r, bp_leg_l, bp_leg_r, bp_torso, islot_armor::covers, find_armor_data(), is_gun(), LEFT, num_sides, body_part_set::reset(), RIGHT, body_part_set::set(), and islot_armor::sided.

◆ get_enchantments()

const std::vector< enchantment > & item::get_enchantments ( ) const

Definition at line 7003 of file item.cpp.

7004{
7005 if( !is_relic() ) {
7006 static const std::vector<enchantment> fallback;
7007 return fallback;
7008 }
7009 return relic_data->get_enchantments();
7010}
bool is_relic() const
Definition: item.cpp:6998

References is_relic(), and relic_data.

Referenced by bonus_from_enchantments(), bonus_from_enchantments_wielded(), process_relic(), and Character::recalculate_enchantment_cache().

◆ get_encumber()

int item::get_encumber ( const Character p) const

Returns the encumbrance value that this item has when worn by given player.

Returns 0 if this is can not be worn at all.

Definition at line 5817 of file item.cpp.

5818{
5819
5820 units::volume contents_volume( 0_ml );
5821
5822 contents_volume += contents.item_size_modifier();
5823
5824 if( p.is_worn( *this ) ) {
5825 const islot_armor *t = find_armor_data();
5826
5827 if( t != nullptr && t->max_encumber != 0 ) {
5828 units::volume char_storage( 0_ml );
5829
5830 for( const item &e : p.worn ) {
5831 char_storage += e.get_storage();
5832 }
5833
5834 if( char_storage != 0_ml ) {
5835 // Cast up to 64 to prevent overflow. Dividing before would prevent this but lose data.
5836 contents_volume += units::from_milliliter( static_cast<int64_t>( t->storage.value() ) *
5837 p.inv.volume().value() / char_storage.value() );
5838 }
5839 }
5840 }
5841
5842 return get_encumber_when_containing( p, contents_volume );
5843}
inventory inv
Definition: character.h:1581
std::list< item > worn
Definition: character.h:1569
bool is_worn(const item &thing) const
Definition: character.h:1099
units::volume volume() const
Definition: inventory.cpp:1060
units::volume item_size_modifier() const
constexpr quantity< value_type, volume_in_milliliter_tag > from_milliliter(const value_type v)
Definition: units_volume.h:25
int max_encumber
When storage is full, how much it encumbers the player.
Definition: itype.h:250
units::volume storage
How much storage this items provides when worn.
Definition: itype.h:275

References contents, find_armor_data(), units::from_milliliter(), get_encumber_when_containing(), get_storage(), Character::inv, Character::is_worn(), item_contents::item_size_modifier(), islot_armor::max_encumber, islot_armor::storage, units::quantity< V, U >::value(), inventory::volume(), and Character::worn.

Referenced by armor_fit_info(), armor_info(), armor_inventory_preset::armor_inventory_preset(), repair_item_actor::can_repair_target(), Character::can_wear(), anonymous_namespace{armor_layers.cpp}::clothing_properties(), repair_item_actor::default_action(), Character::head_cloth_encumbrance(), Character::item_wear_cost(), layer_item(), tname(), and sew_advanced_actor::use().

◆ get_encumber_when_containing()

int item::get_encumber_when_containing ( const Character p,
const units::volume contents_volume 
) const

Returns the encumbrance value that this item has when worn by given player, when containing a particular volume of contents.

Returns 0 if this can not be worn at all.

Definition at line 5845 of file item.cpp.

5847{
5848 const islot_armor *t = find_armor_data();
5849 if( t == nullptr ) {
5850 // handle wearable guns (e.g. shoulder strap) as special case
5851 return is_gun() ? volume() / 750_ml : 0;
5852 }
5853 int encumber = t->encumber;
5854
5855 // Non-rigid items add additional encumbrance proportional to their volume
5856 if( !type->rigid ) {
5857 const int capacity = get_total_capacity().value();
5858
5859 if( t->max_encumber != 0 ) {
5860
5861 if( capacity > 0 ) {
5862 // Cast up to 64 to prevent overflow. Dividing before would prevent this but lose data.
5863 encumber += static_cast<int64_t>( t->max_encumber - t->encumber ) * contents_volume.value() /
5864 capacity;
5865 } else {
5866 debugmsg( "Non-rigid item (%s) without storage capacity.", tname() );
5867 }
5868 } else {
5869 encumber += contents_volume / 500_ml;
5870 }
5871 }
5872
5873 // Fit checked before changes, fitting shouldn't reduce penalties from patching.
5874 if( has_flag( flag_FIT ) && has_flag( flag_VARSIZE ) ) {
5875 encumber = std::max( encumber / 2, encumber - 10 );
5876 }
5877
5878 // TODO: Should probably have sizing affect coverage
5879 const sizing sizing_level = get_sizing( p, encumber != 0 );
5880 switch( sizing_level ) {
5883 // non small characters have a HARD time wearing undersized clothing
5884 encumber *= 3;
5885 break;
5888 // clothes bag up around smol characters and encumber them more
5889 encumber *= 2;
5890 break;
5891 default:
5892 break;
5893 }
5894
5895 encumber += static_cast<int>( std::ceil( get_clothing_mod_val( clothing_mod_type_encumbrance ) ) );
5896
5897 return encumber;
5898}
@ clothing_mod_type_encumbrance
Definition: clothing_mod.h:22
int encumber
How much this item encumbers the player.
Definition: itype.h:246

References big_sized_small_char, clothing_mod_type_encumbrance, debugmsg, islot_armor::encumber, find_armor_data(), flag_FIT(), flag_VARSIZE(), get_clothing_mod_val(), get_sizing(), get_total_capacity(), has_flag(), human_sized_small_char, is_gun(), islot_armor::max_encumber, itype::rigid, small_sized_big_char, small_sized_human_char, tname(), type, units::quantity< V, U >::value(), and volume().

Referenced by armor_info(), and get_encumber().

◆ get_env_resist()

int item::get_env_resist ( int  override_base_resist = 0) const

Returns the resistance to environmental effects (islot_armor::env_resist) that this item provides when worn.

See player::get_env_resist. Higher values are better. For non-armor it returns 0.

Parameters
override_base_resistPass this to artifically increase the base resistance, so that the function can take care of other modifications to resistance for you. Note that this parameter will never decrease base resistnace.

Definition at line 5788 of file item.cpp.

5789{
5790 const islot_armor *t = find_armor_data();
5791 if( t == nullptr ) {
5792 return is_pet_armor() ? type->pet_armor->env_resist : 0;
5793 }
5794 // modify if item is a gas mask and has filter
5795 int resist_base = t->env_resist;
5796 int resist_filter = get_var( "overwrite_env_resist", 0 );
5797 int resist = std::max( { resist_base, resist_filter, override_base_resist } );
5798
5799 return std::lround( resist * get_relative_health() );
5800}
float get_relative_health() const
Relative item health.
Definition: item.cpp:6246
int env_resist
Resistance to environmental effects.
Definition: itype.h:263

References islot_armor::env_resist, find_armor_data(), get_relative_health(), get_var(), is_pet_armor(), itype::pet_armor, and type.

Referenced by acid_resist(), armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), fire_resist(), and tutorial_game::post_action().

◆ get_explosion_data()

struct fuel_explosion item::get_explosion_data ( )

Definition at line 6856 of file item.cpp.

6857{
6858 static struct fuel_explosion null_data;
6859 return has_explosion_data() ? type->fuel->explosion_data : null_data;
6860}
bool has_explosion_data() const
Definition: item.cpp:6851

References type.

Referenced by vehicle::explode_fuel().

◆ get_flags()

const item::FlagsSetType & item::get_flags ( ) const

returs read-only set of flags of this item (not including flags from item type or gunmods)

Definition at line 5378 of file item.cpp.

5379{
5380 return item_tags;
5381}

References item_tags.

Referenced by final_info().

◆ get_food() [1/2]

item * item::get_food ( )

Definition at line 6667 of file item.cpp.

6668{
6669 return get_food_impl( this );
6670}
static Item * get_food_impl(Item *it)
Definition: item.cpp:6656

References get_food_impl().

Referenced by basic_info(), color_in_inventory(), npc::consume_food(), npc::decide_needs(), zone_manager::get_near_zone_type_for_item(), and info().

◆ get_food() [2/2]

const item * item::get_food ( ) const

Definition at line 6672 of file item.cpp.

6673{
6674 return get_food_impl( this );
6675}

References get_food_impl().

◆ get_free_mod_locations()

int item::get_free_mod_locations ( const gunmod_location location) const

Number of mods that can still be installed into the given mod location, for non-guns it always returns 0.

Definition at line 4115 of file item.cpp.

4116{
4117 if( !is_gun() ) {
4118 return 0;
4119 }
4120
4121 std::map<gunmod_location, int> mod_locations = get_mod_locations();
4122
4123 const auto loc = mod_locations.find( location );
4124 if( loc == mod_locations.end() ) {
4125 return 0;
4126 }
4127 int result = loc->second;
4128 for( const item *elem : contents.all_items_top() ) {
4129 const cata::value_ptr<islot_gunmod> &mod = elem->type->gunmod;
4130 if( mod && mod->location == location ) {
4131 result--;
4132 }
4133 }
4134 return result;
4135}
This class is essentially a copyable unique pointer.
Definition: value_ptr.h:19
std::map< gunmod_location, int > get_mod_locations() const
Get mod locations, including those added by other mods.
Definition: item.cpp:4098

References item_contents::all_items_top(), contents, get_mod_locations(), and is_gun().

Referenced by saw_stock_actor::can_use_on(), gun_info(), avatar_funcs::gunmod_remove(), and is_gunmod_compatible().

◆ get_gun_ups_drain()

int item::get_gun_ups_drain ( ) const

Definition at line 9961 of file item.cpp.

9962{
9963 int draincount = 0;
9964 if( type->gun ) {
9965 int modifier = 0;
9966 float multiplier = 1.0f;
9967 for( const item *mod : gunmods() ) {
9968 modifier += mod->type->gunmod->ups_charges_modifier;
9969 multiplier *= mod->type->gunmod->ups_charges_multiplier;
9970 }
9971 draincount = ( type->gun->ups_charges * multiplier ) + modifier;
9972 }
9973 return draincount;
9974}

References itype::gun, gunmods(), and type.

Referenced by character_funcs::ammo_count_for(), npc::decide_needs(), ranged::fire_gun(), ranged::gunmode_checks_weapon(), turret_data::query(), item_funcs::shots_remaining(), and target_ui::update_ammo_range_from_gun_mode().

◆ get_layer()

layer_level item::get_layer ( ) const

Returns clothing layer for item.

Definition at line 5900 of file item.cpp.

5901{
5902 if( type->armor ) {
5903 // We assume that an item will never have per-item flags defining its
5904 // layer, so we can defer to the itype.
5905 return type->layer;
5906 }
5907
5908 if( has_flag( flag_PERSONAL ) ) {
5909 return PERSONAL_LAYER;
5910 } else if( has_flag( flag_SKINTIGHT ) ) {
5911 return UNDERWEAR_LAYER;
5912 } else if( has_flag( flag_WAIST ) ) {
5913 return WAIST_LAYER;
5914 } else if( has_flag( flag_OUTER ) ) {
5915 return OUTER_LAYER;
5916 } else if( has_flag( flag_BELTED ) ) {
5917 return BELTED_LAYER;
5918 } else if( has_flag( flag_AURA ) ) {
5919 return AURA_LAYER;
5920 } else {
5921 return REGULAR_LAYER;
5922 }
5923}
@ WAIST_LAYER
Definition: enums.h:222
@ UNDERWEAR_LAYER
Definition: enums.h:218
@ REGULAR_LAYER
Definition: enums.h:220
@ BELTED_LAYER
Definition: enums.h:226
@ PERSONAL_LAYER
Definition: enums.h:216
@ AURA_LAYER
Definition: enums.h:228
@ OUTER_LAYER
Definition: enums.h:224
layer_level layer
Definition: itype.h:996

References itype::armor, AURA_LAYER, BELTED_LAYER, flag_AURA(), flag_BELTED(), flag_OUTER(), flag_PERSONAL(), flag_SKINTIGHT(), flag_WAIST(), has_flag(), itype::layer, OUTER_LAYER, PERSONAL_LAYER, REGULAR_LAYER, type, UNDERWEAR_LAYER, and WAIST_LAYER.

Referenced by Character::item_wear_cost(), profession::items(), and layer_item().

◆ get_making()

const recipe & item::get_making ( ) const

Get the stored recipe for in progress crafts.

Causes a debugmsg if called on a non-craft and returns the null recipe.

Returns
the recipe in progress

Definition at line 10118 of file item.cpp.

10119{
10120 if( !craft_data_ ) {
10121 debugmsg( "'%s' is not a craft or has a null recipe", tname() );
10122 static const recipe dummy{};
10123 return dummy;
10124 }
10125 assert( craft_data_->making );
10126 return *craft_data_->making;
10127}

References craft_data_, debugmsg, and tname().

Referenced by iuse::craft(), handle_craft_failure(), and set_next_failure_point().

◆ get_min_str()

int item::get_min_str ( ) const

Definition at line 10073 of file item.cpp.

10074{
10075 if( type->gun ) {
10076 int min_str = type->min_str;
10077 for( const item *mod : gunmods() ) {
10078 min_str += mod->type->gunmod->min_str_required_mod;
10079 }
10080 return min_str > 0 ? min_str : 0;
10081 } else {
10082 return type->min_str;
10083 }
10084}
int min_str
Definition: itype.h:905

References itype::gun, gunmods(), itype::min_str, and type.

Referenced by basic_info(), Character::enumerate_unmet_requirements(), ranged::get_str_draw_penalty(), aim_activity_actor::load_RAS_weapon(), Character::meets_stat_requirements(), ranged::str_draw_damage_modifier(), ranged::str_draw_dispersion_modifier(), and ranged::str_draw_range_modifier().

◆ get_mod_locations()

std::map< gunmod_location, int > item::get_mod_locations ( ) const

Get mod locations, including those added by other mods.

Definition at line 4098 of file item.cpp.

4099{
4100 std::map<gunmod_location, int> mod_locations = type->gun->valid_mod_locations;
4101
4102 for( const item *mod : gunmods() ) {
4103 if( !mod->type->gunmod->add_mod.empty() ) {
4104 std::map<gunmod_location, int> add_locations = mod->type->gunmod->add_mod;
4105
4106 for( const std::pair<const gunmod_location, int> &add_location : add_locations ) {
4107 mod_locations[add_location.first] += add_location.second;
4108 }
4109 }
4110 }
4111
4112 return mod_locations;
4113}

References itype::gun, gunmods(), and type.

Referenced by get_free_mod_locations(), gun_info(), avatar_funcs::gunmod_remove(), and is_gunmod_compatible().

◆ get_mtype()

const mtype * item::get_mtype ( ) const
Returns
The monster type associated with this item (corpse). It is usually the type that this item is made of (e.g. corpse, meat or blood of the monster). May return a null-pointer.

Definition at line 6650 of file item.cpp.

6651{
6652 return corpse;
6653}

References corpse.

Referenced by computer_session::action_blood_anal(), burn(), activity_handlers::butcher_finish(), butcher_time_to_cut(), butchery_drops_harvest(), butchery_quarter(), consider_butchery(), editmap::draw_main_ui_overlay(), and game::revive_corpse().

◆ get_next_failure_point()

int item::get_next_failure_point ( ) const

Get the failure point stored in this item.

returns INT_MAX if the failure point is unset. Causes a debugmsg and returns INT_MAX if called on a non-craft.

Returns
an integer >= 0 representing a percent to 5 decimal places. 67.32 percent would be represented as 6732000

Definition at line 895 of file crafting.cpp.

896{
897 if( !is_craft() ) {
898 debugmsg( "get_next_failure_point() called on non-craft '%s.' Aborting.", tname() );
899 return INT_MAX;
900 }
901 return craft_data_->next_failure_point >= 0 ? craft_data_->next_failure_point : INT_MAX;
902}

References craft_data_, debugmsg, is_craft(), and tname().

◆ get_old_owner()

faction_id item::get_old_owner ( ) const

Definition at line 1288 of file item.cpp.

1289{
1291 return old_owner;
1292}
faction_id old_owner
Definition: item.h:2231
void validate_ownership() const
Definition: item.cpp:1294

References old_owner, and validate_ownership().

Referenced by is_old_owner().

◆ get_owner()

faction_id item::get_owner ( ) const

Definition at line 1282 of file item.cpp.

1283{
1285 return owner;
1286}

References owner, and validate_ownership().

Referenced by get_owner_name(), handle_pickup_ownership(), is_owned_by(), and query_consume_ownership().

◆ get_owner_name()

std::string item::get_owner_name ( ) const

Definition at line 1264 of file item.cpp.

1265{
1266 if( !g->faction_manager_ptr->get( get_owner() ) ) {
1267 debugmsg( "item::get_owner_name() item %s has no valid nor null faction id ", tname() );
1268 return "no owner";
1269 }
1270 return g->faction_manager_ptr->get( get_owner() )->name;
1271}
faction_id get_owner() const
Definition: item.cpp:1282

References debugmsg, g, get_owner(), and tname().

Referenced by basic_info().

◆ get_pet_armor_bodytype()

std::string item::get_pet_armor_bodytype ( ) const

Definition at line 5966 of file item.cpp.

5967{
5968 return is_pet_armor() ? type->pet_armor->bodytype : "";
5969}

References is_pet_armor(), itype::pet_armor, and type.

◆ get_pet_armor_max_vol()

units::volume item::get_pet_armor_max_vol ( ) const

Definition at line 5956 of file item.cpp.

5957{
5958 return is_pet_armor() ? type->pet_armor->max_vol : 0_ml;
5959}

References is_pet_armor(), itype::pet_armor, and type.

◆ get_pet_armor_min_vol()

units::volume item::get_pet_armor_min_vol ( ) const

Definition at line 5961 of file item.cpp.

5962{
5963 return is_pet_armor() ? type->pet_armor->min_vol : 0_ml;
5964}

References is_pet_armor(), itype::pet_armor, and type.

◆ get_plant_epoch()

time_duration item::get_plant_epoch ( ) const

Time it takes to grow from one stage to another.

There are 4 plant stages: seed, seedling, mature and harvest. Non-seed items return 0.

Definition at line 9808 of file item.cpp.

9809{
9810 if( !type->seed ) {
9811 return 0_turns;
9812 }
9813 // Growing times have been based around real world season length rather than
9814 // the default in-game season length to give
9815 // more accuracy for longer season lengths
9816 // Also note that seed->grow is the time it takes from seeding to harvest, this is
9817 // divided by 3 to get the time it takes from one plant state to the next.
9818 // TODO: move this into the islot_seed
9819 return type->seed->grow * calendar::season_ratio() / 3;
9820}
float season_ratio()
Definition: calendar.cpp:485
cata::value_ptr< islot_seed > seed
Definition: itype.h:833

References calendar::season_ratio(), itype::seed, and type.

◆ get_plant_name()

std::string item::get_plant_name ( ) const

The name of the plant as it appears in the various informational menus.

This should be translated. Returns an empty string for non-seed items.

Definition at line 9822 of file item.cpp.

9823{
9824 if( !type->seed ) {
9825 return std::string{};
9826 }
9827 return type->seed->plant_name.translated();
9828}

References itype::seed, and type.

Referenced by map::rotten_item_spawn().

◆ get_property_int64_t()

int64_t item::get_property_int64_t ( const std::string &  prop,
int64_t  def = 0 
) const

Definition at line 5394 of file item.cpp.

5395{
5396 const auto it = type->properties.find( prop );
5397 if( it != type->properties.end() ) {
5398 char *e = nullptr;
5399 int64_t r = std::strtoll( it->second.c_str(), &e, 10 );
5400 if( !it->second.empty() && *e == '\0' ) {
5401 return r;
5402 }
5403 debugmsg( "invalid property '%s' for item '%s'", prop.c_str(), tname() );
5404 }
5405 return def;
5406}
std::map< std::string, std::string > properties
Definition: itype.h:883

References debugmsg, itype::properties, tname(), and type.

Referenced by ranged::throw_item().

◆ get_property_string()

std::string item::get_property_string ( const std::string &  prop,
const std::string &  def = "" 
) const

Get typed property for item.

Return same type as the passed default value, or string where no default provided

Definition at line 5388 of file item.cpp.

5389{
5390 const auto it = type->properties.find( prop );
5391 return it != type->properties.end() ? it->second : def;
5392}

References itype::properties, and type.

Referenced by iuse::capture_monster_act().

◆ get_qualities()

std::map< quality_id, int > item::get_qualities ( ) const

Definition at line 5455 of file item.cpp.

5456{
5457 std::map<quality_id, int> qualities;
5458 for( const auto &quality : type->qualities ) {
5459 qualities[quality.first] = get_quality( quality.first );
5460 }
5461 return qualities;
5462}
int get_quality(const quality_id &id) const
Definition: item.cpp:5408
std::map< quality_id, int > qualities
Definition: itype.h:882

References get_quality(), itype::qualities, and type.

Referenced by inventory::update_quality_cache().

◆ get_quality()

int item::get_quality ( const quality_id id) const

EXCEPTION: Items with quality BOIL only count as such if they are empty, excluding items of their ammo type if they are tools.

Definition at line 5408 of file item.cpp.

5409{
5410 int return_quality = INT_MIN;
5411
5412 /**
5413 * EXCEPTION: Items with quality BOIL only count as such if they are empty,
5414 * excluding items of their ammo type if they are tools.
5415 */
5416 auto block_boil_filter = [this]( const item & itm ) {
5417 // We want to skip (do not block) only those : correct ammo, correct magazine, correct toolmod.Everything else should block.
5418 if( &itm == this ) {
5419 // Do not block if checking itself - we are checking only item contents not item itself.
5420 return false;
5421 } else if( itm.is_ammo() ) {
5422 return ammo_types().count( itm.ammo_type() ) == 0;
5423 } else if( itm.is_magazine() ) {
5424 // we want to return "fine for boiling" if any of the ammo types match and "blocks boiling" if none match.
5425 for( const ammotype &at : ammo_types() ) {
5426 for( const ammotype &mag_at : itm.ammo_types() ) {
5427 if( at == mag_at ) {
5428 return false;
5429 }
5430 }
5431 }
5432 return true;
5433 } else if( itm.is_toolmod() ) {
5434 return false;
5435 }
5436 return true;
5437 };
5438 // if it's has boil quality and it's empty, it's good to boil. If it's not empty and it's not a tool (it's probably a container), it's not good to boil. If it's a tool, it gets an extra chance: if it's only contents are mods or batteries, it's still good.
5439 // Also we are using inverted filter, since we don't care about items that the filter likes, we only care if it find something it doesn't like.
5440 if( id == quality_id( "BOIL" ) && !contents.empty() &&
5441 ( !is_tool() || has_item_with( block_boil_filter ) ) ) {
5442 return INT_MIN;
5443 }
5444
5445 for( const std::pair<const quality_id, int> &quality : type->qualities ) {
5446 if( quality.first == id ) {
5447 return_quality = quality.second;
5448 }
5449 }
5450 return_quality = std::max( return_quality, contents.best_quality( id ) );
5451
5452 return return_quality;
5453}
int best_quality(const quality_id &id) const
string_id< quality > quality_id
Definition: type_id.h:184

References ammo_types(), item_contents::best_quality(), contents, item_contents::empty(), visitable< item >::has_item_with(), is_tool(), itype::qualities, and type.

Referenced by iuse::clear_rubble(), iuse::crowbar(), dig_pit_moves_and_byproducts(), get_qualities(), bionic::get_quality(), has_quality_internal(), Character::item_with_best_of_quality(), activity_handlers::lockpicking_finish(), max_quality_internal(), and pick_lock_actor::use().

◆ get_random_material()

const material_type & item::get_random_material ( ) const

Get a material reference to a random material that this item is made of.

This might return the null-material, you may check this with material_type::ident. Note that this may also return a different material each time it's invoked (if the item is made from several materials).

Definition at line 7171 of file item.cpp.

7172{
7173 return random_entry( made_of(), material_id::NULL_ID() ).obj();
7174}
V random_entry(const C &container, D default_value)
Returns a random entry in the container.
Definition: rng.h:88

References made_of(), string_id< material_type >::NULL_ID(), and random_entry().

Referenced by Character::armor_absorb().

◆ get_relative_health()

float item::get_relative_health ( ) const

Relative item health.

Returns 1 for undamaged ||items, values in the range (0, 1) for damaged items and values above 1 for reinforced ++items.

Definition at line 6246 of file item.cpp.

6247{
6248 return ( max_damage() + 1.0f - damage() ) / ( max_damage() + 1.0f );
6249}

References damage(), and max_damage().

Referenced by get_base_env_resist(), and get_env_resist().

◆ get_relative_rot()

double item::get_relative_rot ( ) const

Get rot value relative to shelf life (or 0 if item does not spoil)

Definition at line 5556 of file item.cpp.

5557{
5558 if( goes_bad() ) {
5559 return rot / get_shelf_life();
5560 }
5561 return 0;
5562}
Definition: rot.cpp:11

References get_shelf_life(), and goes_bad().

Referenced by calc_rot(), Character::consume_effects(), fill_with(), Character::fun_for(), comestible_inventory_preset::get_freshness(), get_freshness_description(), get_most_rotten_component(), comestible_inventory_preset::get_time_left(), has_rotten_away(), item(), and rate_food().

◆ get_relic_recharge_scheme()

const std::vector< relic_recharge > & item::get_relic_recharge_scheme ( ) const

Definition at line 7050 of file item.cpp.

7051{
7052 return relic_data->get_recharge_scheme();
7053}

References relic_data.

Referenced by relic_funcs::process_recharge().

◆ get_reload_time()

int item::get_reload_time ( ) const

Returns the reload time of the gun.

Returns 0 if not a gun.

Definition at line 6553 of file item.cpp.

6554{
6555 if( !is_gun() && !is_magazine() ) {
6556 return 0;
6557 }
6558
6559 int reload_time = is_gun() ? type->gun->reload_time : type->magazine->reload_time;
6560 for( const item *mod : gunmods() ) {
6561 reload_time = static_cast<int>( reload_time * ( 100 + mod->type->gunmod->reload_modifier ) / 100 );
6562 }
6563
6564 return reload_time;
6565}

References itype::gun, gunmods(), is_gun(), is_magazine(), itype::magazine, and type.

Referenced by ideal_ranged_dps(), Character::item_reload_cost(), and item_reload_option::moves().

◆ get_remaining_capacity_for_liquid() [1/2]

int item::get_remaining_capacity_for_liquid ( const item liquid,
bool  allow_bucket = false,
std::string *  err = nullptr 
) const

How much more of this liquid (in charges) can be put in this container.

If this is not a container (or not suitable for the liquid), it returns 0. Note that mixing different types of liquid is not possible. Also note that this works for guns and tools that accept liquid ammo.

Parameters
liquidLiquid to check capacity for
allow_bucketAllow filling non-sealable containers
errMessage to print if no more material will fit

Definition at line 8446 of file item.cpp.

8448{
8449 const auto error = [ &err ]( const std::string & message ) {
8450 if( err != nullptr ) {
8451 *err = message;
8452 }
8453 return 0;
8454 };
8455
8456 int remaining_capacity = 0;
8457
8458 // TODO: (sm) is_reloadable_with and this function call each other and can recurse for
8459 // watertight containers.
8460 if( !is_container() && is_reloadable_with( liquid.typeId() ) ) {
8461 if( ammo_remaining() != 0 && ammo_current() != liquid.typeId() ) {
8462 return error( string_format( _( "You can't mix loads in your %s." ), tname() ) );
8463 }
8464 remaining_capacity = ammo_capacity() - ammo_remaining();
8465 } else if( is_container() ) {
8466 if( !type->container->watertight ) {
8467 return error( string_format( _( "That %s isn't water-tight." ), tname() ) );
8468 } else if( !type->container->seals && ( !allow_bucket || !is_bucket() ) ) {
8469 return error( string_format( is_bucket() ?
8470 _( "That %s must be on the ground or held to hold contents!" )
8471 : _( "You can't seal that %s!" ), tname() ) );
8472 } else if( !contents.empty() && contents.front().typeId() != liquid.typeId() ) {
8473 return error( string_format( _( "You can't mix loads in your %s." ), tname() ) );
8474 }
8475 remaining_capacity = liquid.charges_per_volume( get_container_capacity() );
8476 if( !contents.empty() ) {
8477 remaining_capacity -= contents.front().charges;
8478 }
8479 } else {
8480 return error( string_format( _( "That %1$s won't hold %2$s." ), tname(),
8481 liquid.tname() ) );
8482 }
8483
8484 if( remaining_capacity <= 0 ) {
8485 return error( string_format( _( "Your %1$s can't hold any more %2$s." ), tname(),
8486 liquid.tname() ) );
8487 }
8488
8489 return remaining_capacity;
8490}
std::string message
Definition: mapgen.cpp:411

References _, ammo_capacity(), ammo_current(), ammo_remaining(), charges, charges_per_volume(), itype::container, contents, item_contents::empty(), detail::digits::error, item_contents::front(), get_container_capacity(), is_bucket(), is_container(), is_reloadable_with(), mapgen_defer::message, string_format(), tname(), type, and typeId().

Referenced by add_rain_to_container(), fill_with(), get_remaining_capacity_for_liquid(), is_container_full(), maple_tree_sap_container(), advanced_inventory::move_content(), Character::pour_into(), item_reload_option::qty(), and reload().

◆ get_remaining_capacity_for_liquid() [2/2]

int item::get_remaining_capacity_for_liquid ( const item liquid,
const Character p,
std::string *  err = nullptr 
) const

Definition at line 8492 of file item.cpp.

8494{
8495 const bool allow_bucket = p.is_wielding( *this ) || !p.has_item( *this );
8496 int res = get_remaining_capacity_for_liquid( liquid, allow_bucket, err );
8497
8498 if( res > 0 && !type->rigid && p.inv.has_item( *this ) ) {
8499 const units::volume volume_to_expand = std::max( p.volume_capacity() - p.volume_carried(),
8500 0_ml );
8501
8502 res = std::min( liquid.charges_per_volume( volume_to_expand ), res );
8503
8504 if( res == 0 && err != nullptr ) {
8505 *err = string_format( _( "That %s doesn't have room to expand." ), tname() );
8506 }
8507 }
8508
8509 return res;
8510}
units::volume volume_capacity() const
Definition: character.cpp:2668
bool is_wielding(const item &target) const
Definition: character.cpp:3227
units::volume volume_carried() const
Definition: character.cpp:2540

References _, charges_per_volume(), get_remaining_capacity_for_liquid(), visitable< T >::has_item(), Character::inv, Character::is_wielding(), itype::rigid, string_format(), tname(), type, Character::volume_capacity(), and Character::volume_carried().

◆ get_remaining_chapters()

int item::get_remaining_chapters ( const Character ch) const

Get the number of unread chapters.

If the item is no book or has no chapters, it returns 0. This is a per-character setting, different characters may have different number of unread chapters.

Definition at line 7122 of file item.cpp.

7123{
7124 const std::string var = string_format( "remaining-chapters-%d", ch.getID().get_value() );
7125 return get_var( var, get_chapters() );
7126}

References get_chapters(), character_id::get_value(), get_var(), Character::getID(), and string_format().

Referenced by book_info(), display_name(), character_funcs::get_book_fun_for(), and mark_chapter_as_read().

◆ get_rot()

time_duration item::get_rot ( ) const
inline

Definition at line 860 of file item.h.

860 {
861 return rot;
862 }

Referenced by butchery_drops_harvest(), and has_rotten_away().

◆ get_safe_reference()

safe_reference< item > item::get_safe_reference ( )

Return a pointer-like type that's automatically invalidated if this item is destroyed or assigned-to.

Definition at line 449 of file item.cpp.

450{
451 return anchor.reference_to( this );
452}
safe_reference_anchor anchor
Definition: item.h:2169
safe_reference< T > reference_to(T *object)

References anchor, and safe_reference_anchor::reference_to().

Referenced by active_item_cache::add(), and explosion_handler::ExplosionProcess::move_entity().

◆ get_shelf_life()

time_duration item::get_shelf_life ( ) const

Get the shelf life of the item.

Definition at line 5544 of file item.cpp.

5545{
5546 if( goes_bad() ) {
5547 if( is_food() ) {
5548 return get_comestible()->spoils;
5549 } else if( is_corpse() ) {
5550 return 24_hours;
5551 }
5552 }
5553 return 0_turns;
5554}

References get_comestible(), goes_bad(), is_corpse(), and is_food().

Referenced by basic_info(), calc_rot(), food_info(), get_freshness_description(), get_relative_rot(), process_corpse(), set_relative_rot(), spoilage_sort_order(), and stacks_with().

◆ get_side()

side item::get_side ( ) const

Returns side item currently worn on.

Returns BOTH if item is not sided or no side currently set

Definition at line 811 of file item.cpp.

812{
813 // MSVC complains if directly cast double to enum
814 return static_cast<side>( static_cast<int>( get_var( "lateral",
815 static_cast<int>( side::BOTH ) ) ) );
816}
side
Definition: bodypart.h:67

References BOTH, and get_var().

Referenced by display_name(), get_covered_body_parts(), on_wear(), and swap_side().

◆ get_sizing()

item::sizing item::get_sizing ( const Character p,
bool  wearable 
) const

Definition at line 1180 of file item.cpp.

1181{
1182 if( wearable ) {
1183 const bool small = p.get_size() == MS_TINY;
1184 const bool big = p.get_size() == MS_HUGE;
1185
1186 // due to the iterative nature of these features, something can fit and be undersized/oversized
1187 // but that is fine because we have separate logic to adjust encumberance per each. One day we
1188 // may want to have fit be a flag that only applies if a piece of clothing is sized for you as there
1189 // is a bit of cognitive dissonance when something 'fits' and is 'oversized' and the same time
1190 const bool undersize = has_flag( flag_UNDERSIZE );
1191 const bool oversize = has_flag( flag_OVERSIZE );
1192
1193 if( undersize ) {
1194 if( small ) {
1196 } else if( big ) {
1198 } else {
1200 }
1201 } else if( oversize ) {
1202 if( big ) {
1204 } else if( small ) {
1206 } else {
1208 }
1209 } else {
1210 if( big ) {
1212 } else if( small ) {
1214 } else {
1216 }
1217 }
1218 }
1219 return sizing::not_wearable;
1220
1221}
m_size get_size() const override
Get size class of character.
Definition: character.cpp:573
@ MS_TINY
Definition: creature.h:58
@ MS_HUGE
Definition: creature.h:62
static const std::string flag_UNDERSIZE("UNDERSIZE")
static const std::string flag_OVERSIZE("OVERSIZE")

References big_sized_big_char, big_sized_human_char, big_sized_small_char, flag_OVERSIZE(), flag_UNDERSIZE(), Character::get_size(), has_flag(), human_sized_big_char, human_sized_human_char, human_sized_small_char, MS_HUGE, MS_TINY, not_wearable, small_sized_big_char, small_sized_human_char, and small_sized_small_char.

Referenced by armor_fit_info(), armor_info(), get_encumber_when_containing(), and tname().

◆ get_storage()

units::volume item::get_storage ( ) const

Returns the storage amount (islot_armor::storage) that this item provides when worn.

For non-armor it returns 0. The storage amount increases the volume capacity of the character that wears the item.

Definition at line 5757 of file item.cpp.

5758{
5759 const islot_armor *t = find_armor_data();
5760 if( t == nullptr ) {
5761 return is_pet_armor() ? type->pet_armor->storage : 0_ml;
5762 }
5763 units::volume storage = t->storage;
5765 storage += std::lround( mod ) * units::legacy_volume_factor;
5766
5767 return storage;
5768}
@ clothing_mod_type_storage
Definition: clothing_mod.h:24

References clothing_mod_type_storage, find_armor_data(), get_clothing_mod_val(), is_pet_armor(), units::legacy_volume_factor, itype::pet_armor, islot_armor::storage, and type.

Referenced by animal_armor_info(), armor_info(), armor_inventory_preset::armor_inventory_preset(), anonymous_namespace{armor_layers.cpp}::clothing_properties(), get_encumber(), get_total_capacity(), monexamine::give_items_to(), pickup::obtain_and_tokenize_items(), om_carry_weight_to_trips(), tutorial_game::post_action(), pickup::reorder_for_dropping(), Character::takeoff(), and sew_advanced_actor::use().

◆ get_techniques()

std::set< matec_id > item::get_techniques ( ) const

Returns all the martial art techniques that this items supports.

Definition at line 5500 of file item.cpp.

5501{
5502 std::set<matec_id> result = type->techniques;
5503 result.insert( techniques.begin(), techniques.end() );
5504 return result;
5505}

References techniques, itype::techniques, and type.

Referenced by character_martial_arts::get_all_techniques().

◆ get_thickness()

int item::get_thickness ( ) const

Returns the islot_armor::thickness value, or 0 for non-armor.

Thickness is are relative value that affects the items resistance against bash / cutting / bullet damage.

Definition at line 5934 of file item.cpp.

5935{
5936 const islot_armor *t = find_armor_data();
5937 if( t == nullptr ) {
5938 return is_pet_armor() ? type->pet_armor->thickness : 0;
5939 }
5940 return t->thickness;
5941}
int thickness
TODO: document me.
Definition: itype.h:259

References find_armor_data(), is_pet_armor(), itype::pet_armor, islot_armor::thickness, and type.

Referenced by bash_resist(), bullet_resist(), cut_resist(), clothing_mod::get_mod_val(), and tutorial_game::post_action().

◆ get_total_capacity()

units::volume item::get_total_capacity ( ) const

It returns the maximum volume of any contents, including liquids, ammo, magazines, weapons, etc.

Definition at line 8425 of file item.cpp.

8426{
8428
8429 // Consider various iuse_actors which add containing capability
8430 // Treating these two as special cases for now; if more appear in the
8431 // future then this probably warrants a new method on use_function to
8432 // access this information generically.
8433 if( is_bandolier() ) {
8434 result += dynamic_cast<const bandolier_actor *>
8435 ( type->get_use( "bandolier" )->get_actor_ptr() )->max_stored_volume();
8436 }
8437
8438 if( is_holster() ) {
8439 result += dynamic_cast<const holster_actor *>
8440 ( type->get_use( "holster" )->get_actor_ptr() )->max_stored_volume();
8441 }
8442
8443 return result;
8444}
bool is_holster() const
Definition: item.cpp:6602

References use_function::get_actor_ptr(), get_container_capacity(), get_storage(), itype::get_use(), is_bandolier(), is_holster(), and type.

Referenced by armor_info(), and get_encumber_when_containing().

◆ get_uncraft_components()

std::vector< item_comp > item::get_uncraft_components ( ) const

Returns a list of components used to craft this item or the default components if it wasn't player-crafted.

Definition at line 10086 of file item.cpp.

10087{
10088 std::vector<item_comp> ret;
10089 if( components.empty() ) {
10090 //If item wasn't crafted with specific components use default recipe
10091 std::vector<std::vector<item_comp>> recipe = recipe_dictionary::get_uncraft(
10093 for( std::vector<item_comp> &component : recipe ) {
10094 ret.push_back( component.front() );
10095 }
10096 } else {
10097 //Make a new vector of components from the registered components
10098 for( const item &component : components ) {
10099 auto iter = std::find_if( ret.begin(), ret.end(), [component]( item_comp & obj ) {
10100 return obj.type == component.typeId();
10101 } );
10102
10103 if( iter != ret.end() ) {
10104 iter->count += component.count();
10105 } else {
10106 ret.push_back( item_comp( component.typeId(), component.count() ) );
10107 }
10108 }
10109 }
10110 return ret;
10111}

References components, component::count, recipe::disassembly_requirements(), requirement_data::get_components(), recipe_dictionary::get_uncraft(), cata::hash64_detail::ret, and typeId().

Referenced by disassemble_inventory_preset::disassemble_inventory_preset(), and stacks_with().

◆ get_usable_item()

item * item::get_usable_item ( const std::string &  use_name)

Checks this item and its contents (recursively) for types that have use_function with type use_name.

Returns the first item that does have such type or nullptr if none found.

Definition at line 7990 of file item.cpp.

7991{
7992 item *ret = nullptr;
7994 [&ret, &use_name]( item * it ) {
7995 if( it == nullptr ) {
7996 return VisitResponse::SKIP;
7997 }
7998 if( it->get_use_internal( use_name ) ) {
7999 ret = it;
8000 return VisitResponse::ABORT;
8001 }
8002 return VisitResponse::NEXT;
8003 } );
8004
8005 return ret;
8006}
const use_function * get_use_internal(const std::string &use_name) const
Definition: item.cpp:7982

References get_use_internal(), NEXT, cata::hash64_detail::ret, SKIP, and visitable< item >::visit_items().

Referenced by game::butcher(), activity_handlers::firstaid_finish(), Character::invoke_item(), activity_handlers::longsalvage_finish(), item_action_generator::map_actions_to_items(), activity_handlers::repair_item_finish(), and activity_handlers::start_fire_finish().

◆ get_use()

const use_function * item::get_use ( const std::string &  use_name) const

Returns the pointer to use_function with name use_name assigned to the type of this item or any of its contents.

Checks contents recursively. Returns nullptr if not found.

Definition at line 7964 of file item.cpp.

7965{
7966 const use_function *fun = nullptr;
7968 [&fun, &use_name]( const item * it ) {
7969 if( it == nullptr ) {
7970 return VisitResponse::SKIP;
7971 }
7972 fun = it->get_use_internal( use_name );
7973 if( fun != nullptr ) {
7974 return VisitResponse::ABORT;
7975 }
7976 return VisitResponse::NEXT;
7977 } );
7978
7979 return fun;
7980}

References ABORT, get_use_internal(), NEXT, SKIP, and visitable< item >::visit_items().

Referenced by active_item_cache::add(), game::butcher(), color_in_inventory(), activity_handlers::firstaid_finish(), iuse_transform::info(), activity_handlers::longsalvage_finish(), item_action_generator::map_actions_to_items(), on_takeoff(), on_wear(), process_tool(), read(), active_item_cache::remove(), activity_handlers::repair_item_finish(), sleep(), activity_handlers::start_fire_finish(), avatar::wield(), avatar_action::wield(), and npc::wield_better_weapon().

◆ get_use_internal()

const use_function * item::get_use_internal ( const std::string &  use_name) const
private

Definition at line 7982 of file item.cpp.

7983{
7984 if( type != nullptr ) {
7985 return type->get_use( use_name );
7986 }
7987 return nullptr;
7988}

References itype::get_use(), and type.

Referenced by get_usable_item(), and get_use().

◆ get_var() [1/4]

std::string item::get_var ( const std::string &  name) const

Get the variable, if it does not exists, returns an empty string.

Definition at line 1073 of file item.cpp.

1074{
1075 return get_var( name, "" );
1076}

References get_var(), and om_direction::name().

◆ get_var() [2/4]

std::string item::get_var ( const std::string &  name,
const std::string &  default_value 
) const

Definition at line 1064 of file item.cpp.

1065{
1066 const auto it = item_vars.find( name );
1067 if( it == item_vars.end() ) {
1068 return default_value;
1069 }
1070 return it->second;
1071}

References item_vars, and om_direction::name().

◆ get_var() [3/4]

tripoint item::get_var ( const std::string &  name,
const tripoint default_value 
) const

Definition at line 1047 of file item.cpp.

1048{
1049 const auto it = item_vars.find( name );
1050 if( it == item_vars.end() ) {
1051 return default_value;
1052 }
1053 std::vector<std::string> values = string_split( it->second, ',' );
1054 return tripoint( atoi( values[0].c_str() ),
1055 atoi( values[1].c_str() ),
1056 atoi( values[2].c_str() ) );
1057}
std::vector< std::string > string_split(const std::string &text_in, char delim_in)
Split string by delimiter.

References item_vars, om_direction::name(), and string_split().

◆ get_var() [4/4]

◆ get_warmth()

int item::get_warmth ( ) const

Returns the warmth value that this item has when worn.

See player class for temperature related code, or player::warmth. Returned values should be positive. A value of 0 indicates no warmth from this item at all (this is also the default for non-armor).

Definition at line 5943 of file item.cpp.

5944{
5945 const islot_armor *t = find_armor_data();
5946 if( t == nullptr ) {
5947 return 0;
5948 }
5949 int result = t->warmth;
5950
5952
5953 return result;
5954}
@ clothing_mod_type_warmth
Definition: clothing_mod.h:23
int warmth
How much warmth this item provides.
Definition: itype.h:271

References clothing_mod_type_warmth, find_armor_data(), get_clothing_mod_val(), and islot_armor::warmth.

Referenced by armor_info(), armor_inventory_preset::armor_inventory_preset(), behavior::character_oracle_t::can_wear_warmer_clothes(), anonymous_namespace{armor_layers.cpp}::clothing_properties(), sew_advanced_actor::use(), and Character::warmth().

◆ get_weight_capacity_bonus()

units::mass item::get_weight_capacity_bonus ( ) const

Returns the weight capacity bonus (islot_armor::weight_capacity_modifier) that this item provides when worn.

For non-armor it returns 0. The bonus is added to the total weight capacity of the character that wears the item.

Definition at line 5779 of file item.cpp.

5780{
5781 const islot_armor *t = find_armor_data();
5782 if( t == nullptr ) {
5783 return 0_gram;
5784 }
5785 return t->weight_capacity_bonus;
5786}
units::mass weight_capacity_bonus
Bonus to weight capacity.
Definition: itype.h:283

References find_armor_data(), and islot_armor::weight_capacity_bonus.

Referenced by armor_info().

◆ get_weight_capacity_modifier()

float item::get_weight_capacity_modifier ( ) const

Returns the weight capacity modifier (islot_armor::weight_capacity_modifier) that this item provides when worn.

For non-armor it returns 1. The modifier is multiplied with the weight capacity of the character that wears the item.

Definition at line 5770 of file item.cpp.

5771{
5772 const islot_armor *t = find_armor_data();
5773 if( t == nullptr ) {
5774 return 1;
5775 }
5776 return t->weight_capacity_modifier;
5777}
float weight_capacity_modifier
Factor modifiying weight capacity.
Definition: itype.h:279

References find_armor_data(), and islot_armor::weight_capacity_modifier.

Referenced by armor_info().

◆ getlight()

bool item::getlight ( float &  luminance,
units::angle width,
units::angle direction 
) const

Directional light emission of the item.

Parameters
luminanceThe amount of light (see lightmap.cpp)
widthIf greater 0, the light is emitted in an arc, this is the angle of it.
directionThe direction of the light arc. In degrees.

Definition at line 8379 of file item.cpp.

8380{
8381 luminance = 0;
8382 width = 0_degrees;
8383 direction = 0_degrees;
8384 if( light.luminance > 0 ) {
8385 luminance = static_cast<float>( light.luminance );
8386 if( light.width > 0 ) { // width > 0 is a light arc
8387 width = units::from_degrees( light.width );
8389 }
8390 return true;
8391 } else {
8392 const int lumint = getlight_emit();
8393 if( lumint > 0 ) {
8394 luminance = static_cast<float>( lumint );
8395 return true;
8396 }
8397 }
8398 return false;
8399}
light_emission light
Definition: item.h:2233
int getlight_emit() const
How much light (see lightmap.cpp) the item emits (it's assumed to be circular).
Definition: item.cpp:8401
direction
Definition: line.h:39
constexpr quantity< double, angle_in_radians_tag > from_degrees(const value_type v)
Definition: units_angle.h:31
unsigned short luminance
Definition: item.h:89
short direction
Definition: item.h:91
short width
Definition: item.h:90

References light_emission::direction, units::from_degrees(), getlight_emit(), light, light_emission::luminance, and light_emission::width.

◆ getlight_emit()

int item::getlight_emit ( ) const

How much light (see lightmap.cpp) the item emits (it's assumed to be circular).

Definition at line 8401 of file item.cpp.

8402{
8403 float lumint = type->light_emission;
8404
8405 if( lumint == 0 ) {
8406 return 0;
8407 }
8408 if( has_flag( flag_CHARGEDIM ) && is_tool() && !has_flag( flag_USE_UPS ) ) {
8409 // Falloff starts at 1/5 total charge and scales linearly from there to 0.
8410 if( ammo_capacity() && ammo_remaining() < ( ammo_capacity() / 5 ) ) {
8411 lumint *= ammo_remaining() * 5.0 / ammo_capacity();
8412 }
8413 }
8414 return lumint;
8415}
static const std::string flag_CHARGEDIM("CHARGEDIM")
unsigned light_emission
Definition: itype.h:968

References ammo_capacity(), ammo_remaining(), flag_CHARGEDIM(), flag_USE_UPS(), has_flag(), is_tool(), itype::light_emission, and type.

Referenced by Character::active_light(), and getlight().

◆ goes_bad()

bool item::goes_bad ( ) const

whether an item is perishable (can rot)

Definition at line 5523 of file item.cpp.

5524{
5527 }
5528 if( has_flag( flag_PROCESSING ) ) {
5529 return false;
5530 }
5531 if( is_corpse() ) {
5532 // Corpses rot only if they are made of rotting materials
5534 }
5535 return is_food() && get_comestible()->spoils != 0_turns;
5536}
bool made_of_any(const std::set< material_id > &mat_idents) const
Check we are made of at least one of a set (e.g.
Definition: item.cpp:6460
static const std::string flag_PROCESSING("PROCESSING")
bool goes_bad_cache_fetch()
Definition: item.cpp:337
bool goes_bad_cache_is_for(const item *i)
Definition: item.cpp:351
std::set< material_id > get_rotting()
Definition: material.cpp:327

References flag_PROCESSING(), get_comestible(), materials::get_rotting(), item_internal::goes_bad_cache_fetch(), item_internal::goes_bad_cache_is_for(), has_flag(), is_corpse(), is_food(), and made_of_any().

Referenced by actualize_rot(), basic_info(), crafting::can_disassemble(), complete_craft(), food_info(), get_most_rotten_component(), get_relative_rot(), get_shelf_life(), goes_bad_after_opening(), item_internal::goes_bad_cache_set(), item(), set_relative_rot(), spoilage_sort_order(), stacks_with(), and tname().

◆ goes_bad_after_opening()

bool item::goes_bad_after_opening ( ) const

whether an item is perishable (can rot), even if it is currently in a preserving container

Definition at line 5538 of file item.cpp.

5539{
5540 return goes_bad() || ( type->container && type->container->preserves &&
5541 !contents.empty() && contents.front().goes_bad() );
5542}

References itype::container, contents, item_contents::empty(), item_contents::front(), goes_bad(), and type.

◆ gun_all_modes()

std::map< gun_mode_id, gun_mode > item::gun_all_modes ( ) const

Get all possible modes for this gun inclusive of any attached gunmods.

Definition at line 7855 of file item.cpp.

7856{
7857 std::map<gun_mode_id, gun_mode> res;
7858
7859 if( !is_gun() || is_gunmod() ) {
7860 return res;
7861 }
7862
7863 std::vector<const item *> opts = gunmods();
7864 opts.push_back( this );
7865
7866 for( const item *e : opts ) {
7867
7868 // handle base item plus any auxiliary gunmods
7869 if( e->is_gun() ) {
7870 for( const std::pair<const gun_mode_id, gun_modifier_data> &m : e->type->gun->modes ) {
7871 // prefix attached gunmods, e.g. M203_DEFAULT to avoid index key collisions
7872 std::string prefix = e->is_gunmod() ? ( std::string( e->typeId() ) += "_" ) : "";
7873 std::transform( prefix.begin(), prefix.end(), prefix.begin(),
7874 static_cast<int( * )( int )>( toupper ) );
7875
7876 const int qty = m.second.qty();
7877
7878 res.emplace( gun_mode_id( prefix + m.first.str() ), gun_mode( m.second.name(),
7879 const_cast<item *>( e ),
7880 qty, m.second.flags() ) );
7881 }
7882
7883 // non-auxiliary gunmods may provide additional modes for the base item
7884 } else if( e->is_gunmod() ) {
7885 for( const std::pair<const gun_mode_id, gun_modifier_data> &m : e->type->gunmod->mode_modifier ) {
7886 //checks for melee gunmod, points to gunmod
7887 if( m.first == gun_mode_REACH ) {
7888 res.emplace( m.first, gun_mode { m.second.name(), const_cast<item *>( e ),
7889 m.second.qty(), m.second.flags() } );
7890 //otherwise points to the parent gun, not the gunmod
7891 } else {
7892 res.emplace( m.first, gun_mode { m.second.name(), const_cast<item *>( this ),
7893 m.second.qty(), m.second.flags() } );
7894 }
7895 }
7896 }
7897 }
7898
7899 return res;
7900}
static const gun_mode_id gun_mode_REACH("REACH")
string_id< gun_mode > gun_mode_id
Definition: type_id.h:68

References gun_mode_REACH, gunmods(), is_gun(), is_gunmod(), prefix, and iexamine::transform().

Referenced by target_ui::action_switch_mode(), npc_ai::best_mode_for_range(), can_fire_turret(), npc::confident_shoot_range(), gun_cycle_mode(), gun_get_mode(), gun_set_mode(), game::handle_action(), and reach_range().

◆ gun_current_mode()

gun_mode item::gun_current_mode ( ) const

Get the current mode for this gun (or an invalid mode if item is not a gun)

Definition at line 7914 of file item.cpp.

7915{
7916 return gun_get_mode( gun_get_mode_id() );
7917}
gun_mode_id gun_get_mode_id() const
Get id of mode a gun is currently set to, e.g.
Definition: item.cpp:7919
gun_mode gun_get_mode(const gun_mode_id &mode) const
Check if gun supports a specific mode returning an invalid/empty mode if not.
Definition: item.cpp:7902

References gun_get_mode(), and gun_get_mode_id().

Referenced by avatar_action::can_fire_weapon(), aim_activity_actor::do_turn(), target_ui::ensure_ranged_gun_mode(), npc::execute_action(), aim_activity_actor::finish(), fire(), turret_data::fire(), character_funcs::fmt_wielded_weapon(), info(), aim_activity_actor::load_RAS_weapon(), npc::method_of_attack(), target_ui::panel_fire_mode_aim(), target_ui::panel_gun_info(), turret_data::post_fire(), turret_data::prepare_fire(), print_aim(), turret_data::query(), gun_actor::shoot(), target_ui::update_ammo_range_from_gun_mode(), and target_ui::update_status().

◆ gun_cycle_mode()

void item::gun_cycle_mode ( )

Switch to the next available firing mode.

Definition at line 7936 of file item.cpp.

7937{
7938 if( !is_gun() || is_gunmod() ) {
7939 return;
7940 }
7941
7942 const gun_mode_id cur = gun_get_mode_id();
7943 const std::map<gun_mode_id, gun_mode> modes = gun_all_modes();
7944
7945 for( auto iter = modes.begin(); iter != modes.end(); ++iter ) {
7946 if( iter->first == cur ) {
7947 if( std::next( iter ) == modes.end() ) {
7948 break;
7949 }
7950 gun_set_mode( std::next( iter )->first );
7951 return;
7952 }
7953 }
7954 gun_set_mode( modes.begin()->first );
7955
7956 return;
7957}
std::map< gun_mode_id, gun_mode > gun_all_modes() const
Get all possible modes for this gun inclusive of any attached gunmods.
Definition: item.cpp:7855
bool gun_set_mode(const gun_mode_id &mode)
Try to set the mode for a gun, returning false if no such mode is possible.
Definition: item.cpp:7927

References gun_all_modes(), gun_get_mode_id(), gun_set_mode(), is_gun(), and is_gunmod().

Referenced by target_ui::ensure_ranged_gun_mode(), and game::handle_action().

◆ gun_damage()

damage_instance item::gun_damage ( bool  with_ammo = true) const

Summed ranged damage, armor piercing, and multipliers for both, of a gun, including values from mods.

Returns empty instance on non-gun items.

Definition at line 7292 of file item.cpp.

7293{
7294 if( !is_gun() ) {
7295 return damage_instance();
7296 }
7297 damage_instance ret = type->gun->damage;
7298
7299 for( const item *mod : gunmods() ) {
7300 ret.add( mod->type->gunmod->damage );
7301 }
7302
7303 if( with_ammo && ammo_data() ) {
7304 ret.add( ammo_data()->ammo->damage );
7305 }
7306
7307 int item_damage = damage_level( 4 );
7308 if( item_damage > 0 ) {
7309 // TODO: This isn't a good solution for multi-damage guns/ammos
7310 for( damage_unit &du : ret ) {
7311 if( du.amount <= 1.0 ) {
7312 continue;
7313 }
7314 du.amount = std::max<float>( 1.0f, du.amount - item_damage * 2 );
7315 }
7316 }
7317
7318 return ret;
7319}

References ammo_data(), damage_level(), itype::gun, gunmods(), is_gun(), cata::hash64_detail::ret, and type.

Referenced by gun_info(), ideal_ranged_dps(), make_gun_projectile(), and weapon_inventory_preset::weapon_inventory_preset().

◆ gun_dispersion()

int item::gun_dispersion ( bool  with_ammo = true,
bool  with_scaling = true 
) const

Summed dispersion of a gun, including values from mods.

Returns 0 on non-gun items.

Definition at line 7245 of file item.cpp.

7246{
7247 if( !is_gun() ) {
7248 return 0;
7249 }
7250 int dispersion_sum = type->gun->dispersion;
7251 for( const item *mod : gunmods() ) {
7252 dispersion_sum += mod->type->gunmod->dispersion;
7253 }
7254 int dispPerDamage = get_option< int >( "DISPERSION_PER_GUN_DAMAGE" );
7255 dispersion_sum += damage_level( 4 ) * dispPerDamage;
7256 dispersion_sum = std::max( dispersion_sum, 0 );
7257 if( with_ammo && ammo_data() ) {
7258 dispersion_sum += ammo_data()->ammo->dispersion;
7259 }
7260 if( !with_scaling ) {
7261 return dispersion_sum;
7262 }
7263
7264 // Dividing dispersion by 15 temporarily as a gross adjustment,
7265 // will bake that adjustment into individual gun definitions in the future.
7266 // Absolute minimum gun dispersion is 1.
7267 double divider = get_option< float >( "GUN_DISPERSION_DIVIDER" );
7268 dispersion_sum = std::max( static_cast<int>( std::round( dispersion_sum / divider ) ), 1 );
7269
7270 return dispersion_sum;
7271}

References itype::ammo, ammo_data(), damage_level(), itype::gun, gunmods(), is_gun(), and type.

Referenced by gun_info().

◆ gun_get_mode()

gun_mode item::gun_get_mode ( const gun_mode_id mode) const

Check if gun supports a specific mode returning an invalid/empty mode if not.

Definition at line 7902 of file item.cpp.

7903{
7904 if( is_gun() ) {
7905 for( const std::pair<const gun_mode_id, gun_mode> &e : gun_all_modes() ) {
7906 if( e.first == mode ) {
7907 return e.second;
7908 }
7909 }
7910 }
7911 return gun_mode();
7912}

References gun_all_modes(), and is_gun().

Referenced by mattack::frag(), gun_current_mode(), mattack::rifle(), and mattack::tankgun().

◆ gun_get_mode_id()

gun_mode_id item::gun_get_mode_id ( ) const

Get id of mode a gun is currently set to, e.g.

DEFAULT, AUTO, BURST

Definition at line 7919 of file item.cpp.

7920{
7921 if( !is_gun() || is_gunmod() ) {
7922 return gun_mode_id();
7923 }
7924 return gun_mode_id( get_var( GUN_MODE_VAR_NAME, "DEFAULT" ) );
7925}
static const std::string GUN_MODE_VAR_NAME("item::mode")

References get_var(), GUN_MODE_VAR_NAME(), is_gun(), and is_gunmod().

Referenced by target_ui::action_switch_mode(), gun_current_mode(), and gun_cycle_mode().

◆ gun_info()

void item::gun_info ( const item mod,
std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2020 of file item.cpp.

2022{
2023 const std::string space = " ";
2024 const islot_gun &gun = *mod->type->gun;
2025 const Skill &skill = *mod->gun_skill();
2026 avatar &viewer = get_avatar();
2027
2028 // many statistics are dependent upon loaded ammo
2029 // if item is unloaded (or is RELOAD_AND_SHOOT) shows approximate stats using default ammo
2030 const item *loaded_mod = mod;
2031 item tmp;
2032 if( mod->ammo_required() && !mod->ammo_remaining() ) {
2033 tmp = *mod;
2034 tmp.ammo_set( mod->magazine_current() ? tmp.common_ammo_default() : tmp.ammo_default() );
2035 if( tmp.ammo_data() == nullptr ) {
2037 info.emplace_back( "GUN",
2038 _( "Weapon <bad>can't be loaded in its current state</bad>." ) );
2039 return;
2040 }
2041 loaded_mod = &tmp;
2042 if( parts->test( iteminfo_parts::GUN_DEFAULT_AMMO ) ) {
2044 info.emplace_back( "GUN",
2045 _( "Weapon is <bad>not loaded</bad>, so stats below assume the default ammo: " ),
2046 string_format( "<stat>%s</stat>",
2047 loaded_mod->ammo_data()->nname( 1 ) ) );
2048 }
2049 }
2050
2051 const itype *curammo = loaded_mod->ammo_data();
2052 if( mod->ammo_required() && !curammo ) {
2053 debugmsg( "curammo is nullptr in item::gun_info()" );
2054 return;
2055 }
2056 damage_unit gun_du = gun_damage( false ).damage_units.front();
2057
2059
2060 const damage_unit &ammo_du = curammo != nullptr
2061 ? curammo->ammo->damage.damage_units.front()
2062 : damage_unit( DT_STAB, 0 );
2063
2064 if( parts->test( iteminfo_parts::GUN_DAMAGE ) ) {
2066 info.push_back( iteminfo( "GUN", _( "<bold>Ranged damage</bold>: " ), "", iteminfo::no_newline,
2067 gun_du.amount ) );
2068 }
2069
2070 if( mod->ammo_required() ) {
2071 // ammo_damage, sum_of_damage, and ammo_mult not shown so don't need to translate.
2073 assert( curammo ); // Appease clang-tidy
2074 damage_instance ammo_dam = curammo->ammo->damage;
2075 info.push_back( iteminfo( "GUN", "ammo_damage", "",
2077 iteminfo::show_plus, ammo_du.amount ) );
2078 }
2079
2080 if( parts->test( iteminfo_parts::GUN_DAMAGE_TOTAL ) ) {
2081 // Intentionally not using total_damage() as it applies multipliers
2082 info.push_back( iteminfo( "GUN", "sum_of_damage", _( " = <num>" ),
2084 gun_du.amount + ammo_du.amount ) );
2085 }
2086 }
2087 info.back().bNewLine = true;
2088 avatar &you = get_avatar();
2089 int max_gun_range = loaded_mod->gun_range( &you );
2090 if( max_gun_range > 0 && parts->test( iteminfo_parts::GUN_MAX_RANGE ) ) {
2091 info.emplace_back( "GUN", _( "Maximum range: " ), "<num>", iteminfo::no_flags,
2092 max_gun_range );
2093 }
2094
2095 // TODO: This doesn't cover multiple damage types
2096 if( parts->test( iteminfo_parts::GUN_ARMORPIERCE ) ) {
2097 info.push_back( iteminfo( "GUN", _( "Armor-pierce: " ), "",
2099 }
2100 if( mod->ammo_required() ) {
2101 assert( curammo ); // Appease clang-tidy
2102 int ammo_pierce = get_ranged_pierce( *curammo->ammo );
2103 // ammo_armor_pierce and sum_of_armor_pierce don't need to translate.
2105 info.push_back( iteminfo( "GUN", "ammo_armor_pierce", "",
2107 iteminfo::show_plus, ammo_pierce ) );
2108 }
2110 info.push_back( iteminfo( "GUN", "sum_of_armor_pierce", _( " = <num>" ),
2112 get_ranged_pierce( gun ) + ammo_pierce ) );
2113 }
2114 }
2115 info.back().bNewLine = true;
2116
2117 if( parts->test( iteminfo_parts::GUN_DAMAGEMULT ) ) {
2118 info.push_back( iteminfo( "GUN", _( "Damage multiplier: " ), "",
2120 gun_du.damage_multiplier ) );
2121 }
2122
2123 if( mod->ammo_required() ) {
2125 info.push_back( iteminfo( "GUN", "ammo_mult", "*",
2127 ammo_du.damage_multiplier ) );
2128 }
2129
2131 info.push_back( iteminfo( "GUN", "sum_of_damage", _( " = <num>" ),
2133 gun_du.damage_multiplier * ammo_du.damage_multiplier ) );
2134 }
2135 }
2136 info.back().bNewLine = true;
2137
2138 if( parts->test( iteminfo_parts::GUN_ARMORMULT ) ) {
2139 info.push_back( iteminfo( "GUN", _( "Armor multiplier: " ), "",
2141 gun_du.res_mult ) );
2142 }
2143 if( mod->ammo_required() ) {
2145 info.push_back( iteminfo( "GUN", "ammo_armor_mult", _( "*<num>" ),
2148 ammo_du.res_mult ) );
2149 }
2151 info.push_back( iteminfo( "GUN", "final_armor_mult", _( " = <num>" ),
2153 gun_du.res_mult * ammo_du.res_mult ) );
2154 }
2155 }
2156 info.back().bNewLine = true;
2157
2158 if( parts->test( iteminfo_parts::GUN_DISPERSION ) ) {
2159 info.push_back( iteminfo( "GUN", _( "Dispersion: " ), "",
2161 mod->gun_dispersion( false, false ) ) );
2162 }
2163 if( mod->ammo_required() ) {
2164 int ammo_dispersion = curammo->ammo->dispersion;
2165 // ammo_dispersion and sum_of_dispersion don't need to translate.
2167 info.push_back( iteminfo( "GUN", "ammo_dispersion", "",
2170 ammo_dispersion ) );
2171 }
2173 info.push_back( iteminfo( "GUN", "sum_of_dispersion", _( " = <num>" ),
2175 loaded_mod->gun_dispersion( true, false ) ) );
2176 info.push_back( iteminfo( "GUN", "eff_dispersion", _( " (effective: <num>)" ),
2178 static_cast<int>( ranged::get_weapon_dispersion( you, *this ).max() ) ) );
2179 }
2180 }
2181 info.back().bNewLine = true;
2182
2183 // if effective sight dispersion differs from actual sight dispersion display both
2184 int act_disp = mod->sight_dispersion();
2185 int eff_disp = ranged::effective_dispersion( you, act_disp );
2186 int adj_disp = eff_disp - act_disp;
2187
2189 info.push_back( iteminfo( "GUN", _( "Sight dispersion: " ), "",
2191 act_disp ) );
2192
2193 if( adj_disp ) {
2194 info.push_back( iteminfo( "GUN", "sight_adj_disp", "",
2196 iteminfo::no_name | iteminfo::show_plus, adj_disp ) );
2197 info.push_back( iteminfo( "GUN", "sight_eff_disp", _( " = <num>" ),
2199 eff_disp ) );
2200 }
2201 }
2202
2203 bool bipod = mod->has_flag( flag_BIPOD );
2204
2205 if( loaded_mod->gun_recoil() ) {
2207 info.emplace_back( "GUN", _( "Recoil percentage: " ), "",
2209 std::ceil( 100 * loaded_mod->gun_recoil_multiplier() ) );
2210 }
2211 if( bipod && parts->test( iteminfo_parts::GUN_RECOIL_PERCENTAGE_BIPOD ) ) {
2212 info.emplace_back( "GUN", "bipod_recoil_percentage", _( " (with bipod <num>)" ),
2214 std::ceil( 100 * loaded_mod->gun_recoil_multiplier( true ) ) );
2215 }
2216 info.back().bNewLine = true;
2217
2218 if( parts->test( iteminfo_parts::GUN_RECOIL ) ) {
2219 info.emplace_back( "GUN", _( "Effective recoil: " ), "",
2221 loaded_mod->gun_recoil() );
2222 }
2223 if( bipod && parts->test( iteminfo_parts::GUN_RECOIL_BIPOD ) ) {
2224 info.emplace_back( "GUN", "bipod_recoil", _( " (with bipod <num>)" ),
2226 loaded_mod->gun_recoil( true ) );
2227 }
2228 }
2229 info.back().bNewLine = true;
2230
2231 std::map<gun_mode_id, gun_mode> fire_modes = mod->gun_all_modes();
2232 if( parts->test( iteminfo_parts::GUN_BURST_PENALTY ) ) {
2233 if( std::any_of( fire_modes.begin(), fire_modes.end(),
2234 []( const std::pair<gun_mode_id, gun_mode> &e ) {
2235 return e.second.qty > 1 && !e.second.melee();
2236 } ) ) {
2237 info.emplace_back( "GUN", _( "Burst fire penalty: " ), "",
2239 ranged::burst_penalty( you, *this, loaded_mod->gun_recoil() ) );
2240 if( bipod ) {
2241 info.emplace_back( "GUN", "bipod_burst", _( " (with bipod <num>)" ),
2243 ranged::burst_penalty( you, *this, loaded_mod->gun_recoil( true ) ) );
2244 }
2245 }
2246 info.back().bNewLine = true;
2247 }
2248
2249 if( parts->test( iteminfo_parts::GUN_RELOAD_TIME ) ) {
2250 info.emplace_back( "GUN", _( "Reload time: " ),
2251 has_flag( flag_RELOAD_ONE ) ? _( "<num> moves per round" ) :
2252 _( "<num> moves " ),
2253 iteminfo::lower_is_better, mod->get_reload_time() );
2254 }
2255
2256 if( parts->test( iteminfo_parts::GUN_USEDSKILL ) ) {
2257 info.push_back( iteminfo( "GUN", _( "Skill used: " ),
2258 "<info>" + skill.name() + "</info>" ) );
2259 }
2260
2261 if( mod->magazine_integral() || mod->magazine_current() ) {
2262 if( mod->magazine_current() && parts->test( iteminfo_parts::GUN_MAGAZINE ) ) {
2263 info.emplace_back( "GUN", _( "Magazine: " ),
2264 string_format( "<stat>%s</stat>",
2265 mod->magazine_current()->tname() ) );
2266 }
2267 if( mod->ammo_capacity() && parts->test( iteminfo_parts::GUN_CAPACITY ) ) {
2268 for( const ammotype &at : mod->ammo_types() ) {
2269 const std::string fmt = string_format( vgettext( "<num> round of %s",
2270 "<num> rounds of %s",
2271 mod->ammo_capacity() ), at->name() );
2272 info.emplace_back( "GUN", _( "Capacity: " ), fmt, iteminfo::no_flags,
2273 mod->ammo_capacity() );
2274 }
2275 }
2276 } else if( parts->test( iteminfo_parts::GUN_TYPE ) ) {
2277 info.emplace_back( "GUN", _( "Type: " ), enumerate_as_string( mod->ammo_types().begin(),
2278 mod->ammo_types().end(), []( const ammotype & at ) {
2279 return at->name();
2281 }
2282
2283 if( mod->ammo_data() && parts->test( iteminfo_parts::AMMO_REMAINING ) ) {
2284 info.emplace_back( "AMMO", _( "Ammunition: " ), string_format( "<stat>%s</stat>",
2285 mod->ammo_data()->nname( mod->ammo_remaining() ) ) );
2286 }
2287
2288 if( mod->get_gun_ups_drain() && parts->test( iteminfo_parts::AMMO_UPSCOST ) ) {
2289 info.emplace_back( "AMMO",
2290 string_format( vgettext( "Uses <stat>%i</stat> charge of UPS per shot",
2291 "Uses <stat>%i</stat> charges of UPS per shot",
2292 mod->get_gun_ups_drain() ),
2293 mod->get_gun_ups_drain() ) );
2294 }
2295
2296 if( parts->test( iteminfo_parts::GUN_AIMING_STATS ) ) {
2298 info.emplace_back( "GUN", _( "<bold>Base aim speed</bold>: " ), "<num>", iteminfo::no_flags,
2300 for( const ranged::aim_type &type : ranged::get_aim_types( you, *mod ) ) {
2301 // Nameless aim levels don't get an entry.
2302 if( type.name.empty() ) {
2303 continue;
2304 }
2305 // For item comparison to work correctly each info object needs a
2306 // distinct tag per aim type.
2307 const std::string tag = "GUN_" + type.name;
2308 info.emplace_back( tag, string_format( "<info>%s</info>", type.name ) );
2309 int max_dispersion = ranged::get_weapon_dispersion( you, *loaded_mod ).max();
2310 int range = range_with_even_chance_of_good_hit( max_dispersion + type.threshold );
2311 info.emplace_back( tag, _( "Even chance of good hit at range: " ),
2312 _( "<num>" ), iteminfo::no_flags, range );
2313 int aim_mv = ranged::gun_engagement_moves( you, *mod, type.threshold );
2314 info.emplace_back( tag, _( "Time to reach aim level: " ), _( "<num> moves " ),
2315 iteminfo::lower_is_better, aim_mv );
2316 }
2317 }
2318
2319 if( parts->test( iteminfo_parts::GUN_FIRE_MODES ) ) {
2320 std::vector<std::string> fm;
2321 for( const std::pair<const gun_mode_id, gun_mode> &e : fire_modes ) {
2322 if( e.second.target == this && !e.second.melee() ) {
2323 fm.emplace_back( string_format( "%s (%i)", e.second.tname(), e.second.qty ) );
2324 }
2325 }
2326 if( !fm.empty() ) {
2328 info.emplace_back( "GUN", _( "<bold>Fire modes</bold>: " ) +
2329 enumerate_as_string( fm ) );
2330 }
2331 }
2332
2335 const std::set<itype_id> compat = magazine_compatible();
2336 info.emplace_back( "DESCRIPTION", _( "<bold>Compatible magazines</bold>: " ) +
2337 enumerate_as_string( compat.begin(), compat.end(), []( const itype_id & id ) {
2338 return item::nname( id );
2339 } ) );
2340 }
2341
2342 if( !gun.valid_mod_locations.empty() && parts->test( iteminfo_parts::DESCRIPTION_GUN_MODS ) ) {
2344
2345 std::string mod_str = _( "<bold>Mods</bold>: " );
2346
2347 std::map<gunmod_location, int> mod_locations = get_mod_locations();
2348
2349 int iternum = 0;
2350 for( std::pair<const gunmod_location, int> &elem : mod_locations ) {
2351 if( iternum != 0 ) {
2352 mod_str += "; ";
2353 }
2354 const int free_slots = ( elem ).second - get_free_mod_locations( elem.first );
2355 mod_str += string_format( "<bold>%d/%d</bold> %s", free_slots, elem.second,
2356 elem.first.name() );
2357 bool first_mods = true;
2358 for( const item *gmod : gunmods() ) {
2359 if( gmod->type->gunmod->location == ( elem ).first ) { // if mod for this location
2360 if( first_mods ) {
2361 mod_str += ": ";
2362 first_mods = false;
2363 } else {
2364 mod_str += ", ";
2365 }
2366 mod_str += string_format( "<stat>%s</stat>", gmod->tname() );
2367 }
2368 }
2369 iternum++;
2370 }
2371 mod_str += ".";
2372 info.push_back( iteminfo( "DESCRIPTION", mod_str ) );
2373 }
2374
2375 if( mod->casings_count() && parts->test( iteminfo_parts::DESCRIPTION_GUN_CASINGS ) ) {
2377 std::string tmp = vgettext( "Contains <stat>%i</stat> casing",
2378 "Contains <stat>%i</stat> casings", mod->casings_count() );
2379 info.emplace_back( "DESCRIPTION", string_format( tmp, mod->casings_count() ) );
2380 }
2381}
@ range
Definition: character.h:104
Definition: skill.h:33
double max() const
Definition: dispersion.cpp:20
int gun_recoil(bool bipod=false) const
Get effective recoil considering handling, loaded ammo and effects of attached gunmods.
Definition: item.cpp:7341
itype_id common_ammo_default(bool conversion=true) const
Get default ammo for the first ammotype common to an item and its current magazine or "NULL" if none ...
Definition: item.cpp:7629
int get_free_mod_locations(const gunmod_location &location) const
Number of mods that can still be installed into the given mod location, for non-guns it always return...
Definition: item.cpp:4115
damage_instance gun_damage(bool with_ammo=true) const
Summed ranged damage, armor piercing, and multipliers for both, of a gun, including values from mods.
Definition: item.cpp:7292
int gun_dispersion(bool with_ammo=true, bool with_scaling=true) const
Summed dispersion of a gun, including values from mods.
Definition: item.cpp:7245
double gun_recoil_multiplier(bool bipod=false) const
Get multiplier on recoil considering handling and attached gunmods.
Definition: item.cpp:7321
int gun_range(const player *p) const
The weapons range in map squares.
Definition: item.cpp:7374
bool empty() const
Whether the underlying string is empty, not matter what the context is or whether translation is need...
constexpr double MAX_RECOIL
static const std::string flag_RELOAD_ONE("RELOAD_ONE")
static const std::string flag_BIPOD("BIPOD")
@ GUN_ARMORPIERCE_LOADEDAMMO
@ GUN_RECOIL_PERCENTAGE_BIPOD
int gun_engagement_moves(const Character &who, const item &gun, int target=0, int start=MAX_RECOIL)
How many moves does it take to aim gun to the target accuracy.
Definition: ranged.cpp:583
float str_draw_damage_modifier(const item &it, const Character &p)
Definition: ranged.cpp:1034
int burst_penalty(const Character &p, const item &gun, int gun_recoil)
Definition: ranged.cpp:2163
std::vector< aim_type > get_aim_types(const Character &who, const item &gun)
Definition: ranged.cpp:1653
int effective_dispersion(const Character &who, int dispersion)
Definition: ranged.cpp:3821
dispersion_sources get_weapon_dispersion(const Character &who, const item &obj)
Get weapon's dispersion value modified accoring to character stats.
Definition: ranged.cpp:1920
double aim_per_move(const Character &who, const item &gun, double recoil)
Calculates aim improvement per move spent aiming at a given.
Definition: ranged.cpp:3920
int range_with_even_chance_of_good_hit(int dispersion)
Definition: ranged.cpp:572
float amount
Definition: damage.h:37
float res_mult
Definition: damage.h:39
std::map< gunmod_location, int > valid_mod_locations
Location for gun mods.
Definition: itype.h:520
@ no_name
Do not print the name.
Definition: item.h:148
translation name
unique string identifier for this type
Definition: itype.h:855

References _, ranged::aim_per_move(), itype::ammo, ammo_data(), ammo_default(), AMMO_REMAINING, ammo_set(), AMMO_UPSCOST, damage_unit::amount, ranged::burst_penalty(), common_ammo_default(), curammo, damage_unit::damage_multiplier, damage_instance::damage_units, debugmsg, DESCRIPTION_GUN_CASINGS, DESCRIPTION_GUN_MODS, DT_STAB, ranged::effective_dispersion(), translation::empty(), enumerate_as_string(), flag_BIPOD(), flag_RELOAD_ONE(), ranged::get_aim_types(), get_avatar(), get_free_mod_locations(), get_mod_locations(), get_ranged_pierce(), ranged::get_weapon_dispersion(), GUN_AIMING_STATS, GUN_ALLOWED_MAGAZINES, GUN_ARMORMULT, GUN_ARMORMULT_LOADEDAMMO, GUN_ARMORMULT_TOTAL, GUN_ARMORPIERCE, GUN_ARMORPIERCE_LOADEDAMMO, GUN_ARMORPIERCE_TOTAL, GUN_BURST_PENALTY, GUN_CAPACITY, gun_damage(), GUN_DAMAGE, GUN_DAMAGE_LOADEDAMMO, GUN_DAMAGE_TOTAL, GUN_DAMAGEMULT, GUN_DAMAGEMULT_AMMO, GUN_DAMAGEMULT_TOTAL, GUN_DEFAULT_AMMO, gun_dispersion(), GUN_DISPERSION, GUN_DISPERSION_LOADEDAMMO, GUN_DISPERSION_SIGHT, GUN_DISPERSION_TOTAL, ranged::gun_engagement_moves(), GUN_FIRE_MODES, GUN_MAGAZINE, GUN_MAX_RANGE, gun_range(), gun_recoil(), GUN_RECOIL, GUN_RECOIL_BIPOD, gun_recoil_multiplier(), GUN_RECOIL_PERCENTAGE, GUN_RECOIL_PERCENTAGE_BIPOD, GUN_RELOAD_TIME, GUN_TYPE, GUN_USEDSKILL, gunmods(), has_flag(), info(), insert_separation_line(), iteminfo::is_decimal, iteminfo::lower_is_better, magazine_compatible(), magazine_integral(), dispersion_sources::max(), MAX_RECOIL, itype::name, Skill::name(), itype::nname(), iteminfo::no_flags, iteminfo::no_name, iteminfo::no_newline, none, range, range_with_even_chance_of_good_hit(), damage_unit::res_mult, second, iteminfo::show_plus, sign::space, ranged::str_draw_damage_modifier(), string_format(), iteminfo_query::test(), type, islot_gun::valid_mod_locations, and vgettext().

Referenced by info().

◆ gun_noise()

item::sound_data item::gun_noise ( bool  burst = false) const

Returns the sound of the gun being fired.

Parameters
burstWhether the gun was fired in burst mode (the sound string is usually different).

Definition at line 1815 of file ranged.cpp.

1816{
1817 if( !is_gun() ) {
1818 return { 0, "" };
1819 }
1820
1821 int noise = type->gun->loudness;
1822 for( const auto mod : gunmods() ) {
1823 noise += mod->type->gunmod->loudness;
1824 }
1825 if( ammo_data() ) {
1826 noise += ammo_data()->ammo->loudness;
1827 }
1828
1829 noise = std::max( noise, 0 );
1830
1832 // Grenade launchers
1833 return { 8, _( "Thunk!" ) };
1834
1835 } else if( ammo_current() == itype_12mm || ammo_current() == itype_metal_rail ) {
1836 // Railguns
1837 return { 24, _( "tz-CRACKck!" ) };
1838
1839 } else if( ammo_current() == itype_flammable || ammo_current() == itype_66mm ||
1841 // Rocket launchers and flamethrowers
1842 return { 4, _( "Fwoosh!" ) };
1843 } else if( ammo_current() == itype_arrow ) {
1844 return { noise, _( "whizz!" ) };
1845 } else if( ammo_current() == itype_bolt ) {
1846 return { noise, _( "thonk!" ) };
1847 }
1848
1849 auto fx = ammo_effects();
1850
1851 if( fx.count( ammo_effect_LASER ) || fx.count( ammo_effect_PLASMA ) ) {
1852 if( noise < 20 ) {
1853 return { noise, _( "Fzzt!" ) };
1854 } else if( noise < 40 ) {
1855 return { noise, _( "Pew!" ) };
1856 } else if( noise < 60 ) {
1857 return { noise, _( "Tsewww!" ) };
1858 } else {
1859 return { noise, _( "Kra-kow!" ) };
1860 }
1861
1862 } else if( fx.count( ammo_effect_LIGHTNING ) ) {
1863 if( noise < 20 ) {
1864 return { noise, _( "Bzzt!" ) };
1865 } else if( noise < 40 ) {
1866 return { noise, _( "Bzap!" ) };
1867 } else if( noise < 60 ) {
1868 return { noise, _( "Bzaapp!" ) };
1869 } else {
1870 return { noise, _( "Kra-koom!" ) };
1871 }
1872
1873 } else if( fx.count( ammo_effect_WHIP ) ) {
1874 return { noise, _( "Crack!" ) };
1875
1876 } else if( noise > 0 ) {
1877 if( noise < 10 ) {
1878 return { noise, burst ? _( "Brrrip!" ) : _( "plink!" ) };
1879 } else if( noise < 150 ) {
1880 return { noise, burst ? _( "Brrrap!" ) : _( "bang!" ) };
1881 } else if( noise < 175 ) {
1882 return { noise, burst ? _( "P-p-p-pow!" ) : _( "blam!" ) };
1883 } else {
1884 return { noise, burst ? _( "Kaboom!" ) : _( "kerblam!" ) };
1885 }
1886 }
1887
1888 return { 0, "" }; // silent weapons
1889}
std::set< ammo_effect_str_id > ammo_effects(bool with_ammo=true) const
Get ammo effects for item optionally inclusive of any resulting from the loaded ammo.
Definition: item.cpp:7645
static const ammo_effect_str_id ammo_effect_WHIP("WHIP")
static const ammo_effect_str_id ammo_effect_LIGHTNING("LIGHTNING")
static const itype_id itype_12mm("12mm")
static const itype_id itype_flammable("flammable")
static const itype_id itype_m235("m235")
static const ammo_effect_str_id ammo_effect_LASER("LASER")
static const itype_id itype_40x46mm("40x46mm")
static const itype_id itype_40x53mm("40x53mm")
static const itype_id itype_bolt("bolt")
static const itype_id itype_84x246mm("84x246mm")
static const itype_id itype_metal_rail("metal_rail")
static const ammo_effect_str_id ammo_effect_PLASMA("PLASMA")
static const itype_id itype_66mm("66mm")
static const itype_id itype_arrow("arrow")

References _, itype::ammo, ammo_current(), ammo_data(), ammo_effect_LASER, ammo_effect_LIGHTNING, ammo_effect_PLASMA, ammo_effect_WHIP, ammo_effects(), itype::gun, gunmods(), is_gun(), itype_12mm, itype_40x46mm, itype_40x53mm, itype_66mm, itype_84x246mm, itype_arrow, itype_bolt, itype_flammable, itype_m235, itype_metal_rail, noise, and type.

Referenced by is_silent(), ranged::make_gun_sound_effect(), and npc::pretend_fire().

◆ gun_range() [1/2]

int item::gun_range ( bool  with_ammo = true) const

Summed range value of a gun, including values from mods.

Returns 0 on non-gun items.

Definition at line 7355 of file item.cpp.

7356{
7357 if( !is_gun() ) {
7358 return 0;
7359 }
7360 int ret = type->gun->range;
7361 for( const item *mod : gunmods() ) {
7362 ret += mod->type->gunmod->range;
7363 }
7364 if( with_ammo && ammo_data() ) {
7365 if( ammo_data()->ammo->shape ) {
7366 ret = ammo_data()->ammo->shape->get_range();
7367 } else {
7368 ret += ammo_data()->ammo->range;
7369 }
7370 }
7371 return std::min( std::max( 0, ret ), RANGE_HARD_CAP );
7372}
static constexpr int RANGE_HARD_CAP

References itype::ammo, ammo_data(), itype::gun, gunmods(), is_gun(), RANGE_HARD_CAP, cata::hash64_detail::ret, and type.

◆ gun_range() [2/2]

int item::gun_range ( const player p) const

The weapons range in map squares.

If the item has an active gunmod, it returns the range of that gunmod, the guns range is returned only when the item has no active gunmod. This function applies to guns and auxiliary gunmods. For other items, 0 is returned. It includes the range given by the ammo.

Parameters
pThe player that uses the weapon, their strength might affect this. It's optional and can be null.

Definition at line 7374 of file item.cpp.

7375{
7376 int ret = gun_range( true );
7377 if( p == nullptr ) {
7378 return ret;
7379 }
7380 if( !p->meets_requirements( *this ) ) {
7381 return 0;
7382 }
7383
7384 // Reduce bow range if player has less than minimum strength.
7385 ret *= ranged::str_draw_range_modifier( *this, *p );
7386
7387 return std::max( 0, ret );
7388}
bool meets_requirements(const item &it, const item &context=item()) const
Checks whether the character meets overall requirements to be able to use the item.
Definition: character.cpp:3542
float str_draw_range_modifier(const item &it, const Character &p)
Definition: ranged.cpp:1060

References gun_range(), Character::meets_requirements(), cata::hash64_detail::ret, and ranged::str_draw_range_modifier().

Referenced by gun_info(), gun_range(), game::list_monsters(), make_gun_projectile(), turret_data::range(), and target_ui::update_ammo_range_from_gun_mode().

◆ gun_recoil()

int item::gun_recoil ( bool  bipod = false) const

Get effective recoil considering handling, loaded ammo and effects of attached gunmods.

Parameters
bipodwhether any bipods should be considered
Returns
effective recoil (per shot) or zero if gun uses ammo and none is loaded

Definition at line 7341 of file item.cpp.

7342{
7343 if( !is_gun() || ( ammo_required() && !ammo_remaining() ) ) {
7344 return 0;
7345 }
7346
7347 int qty = type->gun->recoil;
7348 if( ammo_data() ) {
7349 qty += ammo_data()->ammo->recoil;
7350 }
7351
7352 return qty * gun_recoil_multiplier( bipod );
7353}

References itype::ammo, ammo_data(), ammo_remaining(), ammo_required(), itype::gun, gun_recoil_multiplier(), is_gun(), and type.

Referenced by calculate_dispersion(), npc::confident_gun_mode_range(), ranged::fire_gun(), and gun_info().

◆ gun_recoil_multiplier()

double item::gun_recoil_multiplier ( bool  bipod = false) const

Get multiplier on recoil considering handling and attached gunmods.

Parameters
bipodwhether any bipods should be considered
Returns
multiplier on recoil applied to shots fired from this gun

Definition at line 7321 of file item.cpp.

7322{
7323 double handling = type->gun->handling;
7324 for( const item *mod : gunmods() ) {
7325 if( bipod || !mod->has_flag( flag_BIPOD ) ) {
7326 handling += mod->type->gunmod->handling;
7327 }
7328 }
7329
7330 // Rescale from JSON units which are intentionally specified as integral values
7331 handling /= 10;
7332
7333 // Handling will almost always be above 1.0
7334 if( handling > 1.0 ) {
7335 return 1.0 / handling;
7336 } else {
7337 return 2.0 - handling;
7338 }
7339}

References flag_BIPOD(), itype::gun, gunmods(), and type.

Referenced by gun_info(), and gun_recoil().

◆ gun_set_mode()

bool item::gun_set_mode ( const gun_mode_id mode)

Try to set the mode for a gun, returning false if no such mode is possible.

Definition at line 7927 of file item.cpp.

7928{
7929 if( !is_gun() || is_gunmod() || !gun_all_modes().count( mode ) ) {
7930 return false;
7931 }
7932 set_var( GUN_MODE_VAR_NAME, mode.str() );
7933 return true;
7934}

References count(), gun_all_modes(), GUN_MODE_VAR_NAME(), is_gun(), is_gunmod(), set_var(), and string_id< T >::str().

Referenced by target_ui::action_switch_mode(), gun_cycle_mode(), avatar_funcs::gunmod_remove(), game::handle_action(), io(), and gun_actor::shoot().

◆ gun_skill()

skill_id item::gun_skill ( ) const

◆ gunmod_find() [1/2]

item * item::gunmod_find ( const itype_id mod)

Get first attached gunmod matching type or nullptr if no such mod or item is not a gun.

Definition at line 7762 of file item.cpp.

7763{
7764 std::vector<item *> mods = gunmods();
7765 auto it = std::find_if( mods.begin(), mods.end(), [&mod]( item * e ) {
7766 return e->typeId() == mod;
7767 } );
7768 return it != mods.end() ? *it : nullptr;
7769}

References gunmods().

Referenced by saw_barrel_actor::can_use_on(), saw_stock_actor::can_use_on(), cycle_action(), gunmod_find(), is_gunmod_compatible(), tname(), volume(), and weight().

◆ gunmod_find() [2/2]

const item * item::gunmod_find ( const itype_id mod) const

Definition at line 7771 of file item.cpp.

7772{
7773 return const_cast<item *>( this )->gunmod_find( mod );
7774}
item * gunmod_find(const itype_id &mod)
Get first attached gunmod matching type or nullptr if no such mod or item is not a gun.
Definition: item.cpp:7762

References gunmod_find().

◆ gunmod_info()

void item::gunmod_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2383 of file item.cpp.

2385{
2386 if( !is_gunmod() ) {
2387 return;
2388 }
2389 const islot_gunmod &mod = *type->gunmod;
2390
2391 if( is_gun() && parts->test( iteminfo_parts::DESCRIPTION_GUNMOD ) ) {
2392 info.push_back( iteminfo( "DESCRIPTION",
2393 _( "This mod <info>must be attached to a gun</info>, "
2394 "it can not be fired separately." ) ) );
2395 }
2397 info.push_back( iteminfo( "DESCRIPTION",
2398 _( "When attached to a gun, <good>allows</good> making "
2399 "<info>reach melee attacks</info> with it." ) ) );
2400 }
2401 if( mod.dispersion != 0 && parts->test( iteminfo_parts::GUNMOD_DISPERSION ) ) {
2402 info.push_back( iteminfo( "GUNMOD", _( "Dispersion modifier: " ), "",
2404 mod.dispersion ) );
2405 }
2406 if( mod.sight_dispersion != -1 && parts->test( iteminfo_parts::GUNMOD_DISPERSION_SIGHT ) ) {
2407 info.push_back( iteminfo( "GUNMOD", _( "Sight dispersion: " ), "",
2408 iteminfo::lower_is_better, mod.sight_dispersion ) );
2409 }
2410 if( mod.aim_speed >= 0 && parts->test( iteminfo_parts::GUNMOD_AIMSPEED ) ) {
2411 info.push_back( iteminfo( "GUNMOD", _( "Aim speed: " ), "",
2412 iteminfo::lower_is_better, mod.aim_speed ) );
2413 }
2414 int total_damage = static_cast<int>( mod.damage.total_damage() );
2415 if( total_damage != 0 && parts->test( iteminfo_parts::GUNMOD_DAMAGE ) ) {
2416 info.push_back( iteminfo( "GUNMOD", _( "Damage: " ), "", iteminfo::show_plus,
2417 total_damage ) );
2418 }
2419 int pierce = get_ranged_pierce( mod );
2421 info.push_back( iteminfo( "GUNMOD", _( "Armor-pierce: " ), "", iteminfo::show_plus,
2422 pierce ) );
2423 }
2424 if( mod.handling != 0 && parts->test( iteminfo_parts::GUNMOD_HANDLING ) ) {
2425 info.emplace_back( "GUNMOD", _( "Handling modifier: " ), "",
2426 iteminfo::show_plus, mod.handling );
2427 }
2428 if( !type->mod->ammo_modifier.empty() && parts->test( iteminfo_parts::GUNMOD_AMMO ) ) {
2429 for( const ammotype &at : type->mod->ammo_modifier ) {
2430 info.push_back( iteminfo( "GUNMOD", string_format( _( "Ammo: <stat>%s</stat>" ),
2431 at->name() ) ) );
2432 }
2433 }
2434 if( mod.reload_modifier != 0 && parts->test( iteminfo_parts::GUNMOD_RELOAD ) ) {
2435 info.emplace_back( "GUNMOD", _( "Reload modifier: " ), _( "<num>%" ),
2436 iteminfo::lower_is_better, mod.reload_modifier );
2437 }
2438 if( mod.min_str_required_mod > 0 && parts->test( iteminfo_parts::GUNMOD_STRENGTH ) ) {
2439 info.push_back( iteminfo( "GUNMOD", _( "Minimum strength required modifier: " ),
2440 mod.min_str_required_mod ) );
2441 }
2442 if( !mod.add_mod.empty() && parts->test( iteminfo_parts::GUNMOD_ADD_MOD ) ) {
2444
2445 std::string mod_loc_str = _( "<bold>Adds mod locations: </bold> " );
2446
2447 std::map<gunmod_location, int> mod_locations = mod.add_mod;
2448
2449 int iternum = 0;
2450 for( std::pair<const gunmod_location, int> &elem : mod_locations ) {
2451 if( iternum != 0 ) {
2452 mod_loc_str += "; ";
2453 }
2454 mod_loc_str += string_format( "<bold>%s</bold> %s", elem.second, elem.first.name() );
2455 iternum++;
2456 }
2457 mod_loc_str += ".";
2458 info.push_back( iteminfo( "GUNMOD", mod_loc_str ) );
2459 }
2460
2462
2463 if( parts->test( iteminfo_parts::GUNMOD_USEDON ) ) {
2464 std::string used_on_str = _( "<bold>Used on:</bold>" );
2465
2466 if( !mod.usable.empty() ) {
2467 used_on_str += _( "\n Specific: " ) + enumerate_as_string( mod.usable.begin(),
2468 mod.usable.end(), []( const itype_id & used_on ) {
2469 return string_format( "<info>%s</info>", used_on->nname( 1 ) );
2470 } );
2471 }
2472
2473 if( !mod.usable_category.empty() ) {
2474 used_on_str += _( "\n Category: " );
2475 std::vector<std::string> combination;
2476 for( const std::unordered_set<weapon_category_id> &catgroup : mod.usable_category ) {
2477 combination.emplace_back( ( "[" ) + enumerate_as_string( catgroup.begin(),
2478 catgroup.end(), []( const weapon_category_id & wcid ) {
2479 return string_format( "<info>%s</info>", wcid->name().translated() );
2480 }, enumeration_conjunction::none ) + ( "]" ) );
2481 }
2482 used_on_str += enumerate_as_string( combination, enumeration_conjunction::or_ );
2483 }
2484
2485 info.push_back( iteminfo( "GUNMOD", used_on_str ) );
2486 }
2487
2488 if( parts->test( iteminfo_parts::GUNMOD_LOCATION ) ) {
2489 info.push_back( iteminfo( "GUNMOD", string_format( _( "Location: %s" ),
2490 mod.location.name() ) ) );
2491 }
2492
2493 if( !mod.blacklist_mod.empty() && parts->test( iteminfo_parts::GUNMOD_BLACKLIST_MOD ) ) {
2494 std::string mod_black_str = _( "<bold>Incompatible with mod location: </bold> " );
2495
2496 int iternum = 0;
2497 for( const gunmod_location &black : mod.blacklist_mod ) {
2498 if( iternum != 0 ) {
2499 mod_black_str += ", ";
2500 }
2501 mod_black_str += string_format( "%s", black.name() );
2502 iternum++;
2503 }
2504 mod_black_str += ".";
2505 info.push_back( iteminfo( "GUNMOD", mod_black_str ) );
2506 }
2507}
cata::value_ptr< islot_gunmod > gunmod
Definition: itype.h:828
cata::value_ptr< islot_mod > mod
Definition: itype.h:823

References _, catacurses::black, DESCRIPTION_GUNMOD, DESCRIPTION_GUNMOD_REACH, enumerate_as_string(), flag_REACH_ATTACK(), get_ranged_pierce(), itype::gunmod, GUNMOD_ADD_MOD, GUNMOD_AIMSPEED, GUNMOD_AMMO, GUNMOD_ARMORPIERCE, GUNMOD_BLACKLIST_MOD, GUNMOD_DAMAGE, GUNMOD_DISPERSION, GUNMOD_DISPERSION_SIGHT, GUNMOD_HANDLING, GUNMOD_LOCATION, GUNMOD_RELOAD, GUNMOD_STRENGTH, GUNMOD_USEDON, has_flag(), info(), insert_separation_line(), is_gun(), is_gunmod(), iteminfo::lower_is_better, itype::mod, ammunition_type::name(), none, or_, iteminfo::show_plus, string_format(), iteminfo_query::test(), and type.

Referenced by info().

◆ gunmods() [1/2]

◆ gunmods() [2/2]

std::vector< const item * > item::gunmods ( ) const

Definition at line 7757 of file item.cpp.

7758{
7759 return contents.gunmods();
7760}

References contents, and item_contents::gunmods().

◆ handle_craft_failure()

bool item::handle_craft_failure ( player crafter)

Handle failure during crafting.

Destroy components, lose progress, and set a new failure point.

Parameters
crafterthe crafting player.
Returns
whether the craft being worked on should be entirely destroyed

Definition at line 930 of file crafting.cpp.

931{
932 if( !is_craft() ) {
933 debugmsg( "handle_craft_failure() called on non-craft '%s.' Aborting.", tname() );
934 return false;
935 }
936
937 const double success_roll = crafter.crafting_success_roll( get_making() );
938 const int starting_components = this->components.size();
939 // Destroy at most 75% of the components, always a chance of losing 1 though
940 const size_t max_destroyed = std::max<size_t>( 1, components.size() * 3 / 4 );
941 for( size_t i = 0; i < max_destroyed; i++ ) {
942 // This shouldn't happen
943 if( components.empty() ) {
944 break;
945 }
946 // If we roll success, skip destroying a component
947 if( x_in_y( success_roll, 1.0 ) ) {
948 continue;
949 }
950 destroy_random_component( *this, crafter );
951 }
952 if( starting_components > 0 && this->components.empty() ) {
953 // The craft had components and all of them were destroyed.
954 return true;
955 }
956
957 // Minimum 25% progress lost, average 35%. Falls off exponentially
958 // Loss is scaled by the success roll
959 const double percent_progress_loss = rng_exponential( 0.25, 0.35 ) *
960 ( 1.0 - std::min( success_roll, 1.0 ) );
961 const int progess_loss = item_counter * percent_progress_loss;
962 crafter.add_msg_player_or_npc( _( "You mess up and lose %d%% progress." ),
963 _( "<npcname> messes up and loses %d%% progress." ), progess_loss / 100000 );
964 item_counter = clamp( item_counter - progess_loss, 0, 10000000 );
965
966 set_next_failure_point( crafter );
967
968 // Check if we can consume a new component and continue
969 if( !crafter.can_continue_craft( *this ) ) {
970 crafter.cancel_activity();
971 }
972 return false;
973}
bool x_in_y(const time_duration &a, const time_duration &b)
Definition: calendar.cpp:521
constexpr T clamp(const T &val, const T &min, const T &max)
Clamp first argument so that it is no lower than second and no higher than third.
Definition: cata_utility.h:149
void cancel_activity()
Definition: character.cpp:9230
const recipe & get_making() const
Get the stored recipe for in progress crafts.
Definition: item.cpp:10118
void set_next_failure_point(const player &crafter)
Calculates and sets the next failure point for an in progress craft.
Definition: crafting.cpp:904
void add_msg_player_or_npc(const std::string &player_msg, const std::string &npc_str) const override
Definition: player.cpp:371
bool can_continue_craft(item &craft)
Check if the player meets the requirements to continue the in progress craft and if unable to continu...
Definition: crafting.cpp:1162
double crafting_success_roll(const recipe &making) const
Calculate a value representing the success of the player at crafting the given recipe,...
Definition: crafting.cpp:820
static void destroy_random_component(item &craft, const player &crafter)
Definition: crafting.cpp:917
double rng_exponential(double min, double mean)
Definition: rng.cpp:55

References _, player::add_msg_player_or_npc(), player::can_continue_craft(), Character::cancel_activity(), clamp(), components, player::crafting_success_roll(), debugmsg, destroy_random_component(), get_making(), is_craft(), item_counter, rng_exponential(), set_next_failure_point(), tname(), and x_in_y().

◆ handle_pickup_ownership()

void item::handle_pickup_ownership ( Character c)

Definition at line 4496 of file item.cpp.

4497{
4498 if( is_owned_by( c ) ) {
4499 return;
4500 }
4501 // Add ownership to item if unowned
4502 if( owner.is_null() ) {
4503 set_owner( c );
4504 } else {
4506 if( !is_owned_by( c ) && &c == &you ) {
4507 std::vector<npc *> witnesses;
4508 for( npc &elem : g->all_npcs() ) {
4509 if( rl_dist( elem.pos(), you.pos() ) < MAX_VIEW_DISTANCE && elem.get_faction() &&
4510 is_owned_by( elem ) && elem.sees( you.pos() ) ) {
4511 elem.say( "<witnessed_thievery>", 7 );
4512 npc *npc_to_add = &elem;
4513 witnesses.push_back( npc_to_add );
4514 }
4515 }
4516 if( !witnesses.empty() ) {
4518 // Make sure there is only one witness
4519 for( npc &guy : g->all_npcs() ) {
4520 if( guy.get_attitude() == NPCATT_RECOVER_GOODS ) {
4521 guy.set_attitude( NPCATT_NULL );
4522 }
4523 }
4524 random_entry( witnesses )->set_attitude( NPCATT_RECOVER_GOODS );
4525 // Notify the activity that we got a witness
4526 if( c.activity && !c.activity.is_null() && c.activity.id() == ACT_PICKUP ) {
4527 c.activity.str_values.clear();
4528 c.activity.str_values.emplace_back( has_thievery_witness );
4529 }
4530 }
4531 set_owner( c );
4532 }
4533 }
4534}
const tripoint & pos() const override
Definition: character.cpp:599
bool is_owned_by(const Character &c, bool available_to_take=false) const
Definition: item.cpp:1237
void set_old_owner(const faction_id &temp_owner)
Definition: item.h:2019
void set_owner(const faction_id &new_owner)
Definition: item.h:2025
Definition: npc.h:744
int rl_dist(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:519
static constexpr int MAX_VIEW_DISTANCE
static const activity_id ACT_PICKUP("ACT_PICKUP")
static const std::string has_thievery_witness("has_thievery_witness")
@ NPCATT_NULL
Definition: npc.h:81
@ NPCATT_RECOVER_GOODS
Definition: npc.h:100

References ACT_PICKUP, c, g, get_owner(), get_player_character(), has_thievery_witness(), string_id< T >::is_null(), is_owned_by(), MAX_VIEW_DISTANCE, NPCATT_NULL, NPCATT_RECOVER_GOODS, owner, Character::pos(), random_entry(), rl_dist(), set_old_owner(), and set_owner().

Referenced by on_pickup(), on_wear(), and on_wield().

◆ has_any_flag()

template<typename Container , typename T = std::decay_t<decltype( *std::declval<const Container &>().begin() )>>
bool item::has_any_flag ( const Container &  flags) const
inline

Definition at line 1407 of file item.h.

1407 {
1408 return std::any_of( flags.begin(), flags.end(), [&]( const T & flag ) {
1409 return has_flag( flag );
1410 } );
1411 }

Referenced by Character::can_eat(), and Character::consume_effects().

◆ has_clothing_mod()

bool item::has_clothing_mod ( ) const

Definition at line 10162 of file item.cpp.

10163{
10164 for( const clothing_mod &cm : clothing_mods::get_all() ) {
10165 if( has_own_flag( cm.flag ) ) {
10166 return true;
10167 }
10168 }
10169 return false;
10170}
const std::vector< clothing_mod > & get_all()

References clothing_mods::get_all(), and has_own_flag().

Referenced by tname().

◆ has_effect_when_carried()

bool item::has_effect_when_carried ( art_effect_passive  effect) const

Does the item provide the artifact effect when it is carried?

Definition at line 9786 of file item.cpp.

9787{
9788 if( !type->artifact ) {
9789 return false;
9790 }
9791 const std::vector<art_effect_passive> &ec = type->artifact->effects_carried;
9792 if( std::find( ec.begin(), ec.end(), effect ) != ec.end() ) {
9793 return true;
9794 }
9795 for( const item *i : contents.all_items_top() ) {
9796 if( i->has_effect_when_carried( effect ) ) {
9797 return true;
9798 }
9799 }
9800 return false;
9801}
Definition: effect.h:161
FMT_CONSTEXPR bool find(Ptr first, Ptr last, T value, Ptr &out)
cata::value_ptr< islot_artifact > artifact
Definition: itype.h:834

References item_contents::all_items_top(), itype::artifact, contents, detail::find(), and type.

Referenced by Character::hardcoded_effects(), and Character::has_artifact_with().

◆ has_effect_when_wielded()

bool item::has_effect_when_wielded ( art_effect_passive  effect) const

Does the item provide the artifact effect when it is wielded?

Definition at line 9768 of file item.cpp.

9769{
9770 if( !type->artifact ) {
9771 return false;
9772 }
9773 const std::vector<art_effect_passive> &ew = type->artifact->effects_wielded;
9774 return std::find( ew.begin(), ew.end(), effect ) != ew.end();
9775}

References itype::artifact, detail::find(), and type.

Referenced by Character::hardcoded_effects().

◆ has_effect_when_worn()

bool item::has_effect_when_worn ( art_effect_passive  effect) const

Does the item provide the artifact effect when it is worn?

Definition at line 9777 of file item.cpp.

9778{
9779 if( !type->artifact ) {
9780 return false;
9781 }
9782 const std::vector<art_effect_passive> &ew = type->artifact->effects_worn;
9783 return std::find( ew.begin(), ew.end(), effect ) != ew.end();
9784}

References itype::artifact, detail::find(), and type.

◆ has_explosion_data()

bool item::has_explosion_data ( ) const

Definition at line 6851 of file item.cpp.

6852{
6853 return is_fuel() ? type->fuel->has_explode_data : false;
6854}

References itype::fuel, is_fuel(), and type.

Referenced by vehicle::explode_fuel().

◆ has_fault()

bool item::has_fault ( const fault_id fault) const

Does this item have the specified fault.

Definition at line 5318 of file item.cpp.

5319{
5320 return faults.count( fault );
5321}
Definition: fault.h:29

References faults.

Referenced by install_bionic_actor::can_use(), color_in_inventory(), bionic_install_preset::get_denial(), bionic_install_surgeon_preset::get_denial(), ranged::handle_gun_damage(), bionic_sterilize_preset::is_shown(), and tname().

◆ has_flag() [1/2]

bool item::has_flag ( const flag_str_id flag) const

Definition at line 5352 of file item.cpp.

5353{
5354 return has_flag( flag.str() );
5355}

References has_flag(), and string_id< T >::str().

◆ has_flag() [2/2]

bool item::has_flag ( const std::string &  flag) const

Definition at line 5328 of file item.cpp.

5329{
5330 bool ret = false;
5331
5332 if( json_flag::get( f ).inherit() ) {
5333 for( const item *e : is_gun() ? gunmods() : toolmods() ) {
5334 // gunmods fired separately do not contribute to base gun flags
5335 if( !e->is_gun() && e->has_flag( f ) ) {
5336 return true;
5337 }
5338 }
5339 }
5340
5341 // other item type flags
5342 ret = type->has_flag( f );
5343 if( ret ) {
5344 return ret;
5345 }
5346
5347 // now check for item specific flags
5348 ret = has_own_flag( f );
5349 return ret;
5350}
bool has_flag(const std::string &flag) const
Definition: itype.cpp:146

References json_flag::get(), gunmods(), itype::has_flag(), has_own_flag(), is_gun(), cata::hash64_detail::ret, toolmods(), and type.

Referenced by Character::activate_bionic(), map::add_item(), map::add_item_or_charges(), monexamine::add_leash(), Character::all_items_with_flag(), Character::allergy_type(), npc::alt_attack(), ammo_consume(), ammo_remaining(), ammo_required(), ammo_set(), amount_of_internal(), Character::armor_absorb(), armor_fit_info(), armor_info(), iexamine::autodoc(), autodoc_internal(), basic_info(), mattack::bio_op_disarm(), iuse::blech(), Character::block_hit(), blocking_ability(), Character::burn_fuel(), butcher_time_to_cut(), butchery_drops_harvest(), calc_rot(), iuse::camera(), item_funcs::can_be_unloaded(), Character::can_consume(), can_do_activity_there(), Character::can_eat(), Character::can_feed_furnace_with(), behavior::character_oracle_t::can_make_fire(), repair_item_actor::can_repair_target(), can_revive(), Character::can_swap(), Character::can_takeoff(), Character::can_unwield(), Character::can_use_heal_item(), Character::can_wear(), Character::can_wield(), iuse::capture_monster_act(), iuse::capture_monster_veh(), cast_spell(), check_litcig(), anonymous_namespace{armor_layers.cpp}::clothing_flags_description(), anonymous_namespace{armor_layers.cpp}::clothing_layer(), color_in_inventory(), combat_info(), comestible_inventory_preset::comestible_inventory_preset(), complete_craft(), crafting::complete_disassemble(), Character::compute_effective_nutrients(), Character::compute_nutrient_range(), conductive(), consider_butchery(), Character::consume_charges(), game_menus::inv::consume_drink(), Character::consume_effects(), game_menus::inv::consume_food(), Character::consume_med(), Character::consume_remote_fuel(), vehicle::consumption_per_hour(), corpse_volume(), activity_handlers::cracking_do_turn(), recipe::create_byproducts(), Single_item_creator::create_single(), iexamine::cvdmachine(), cycle_action(), damage_melee(), repair_item_actor::default_action(), iexamine::dimensional_portal(), display_name(), aim_activity_actor::do_turn(), draw_bionics_titlebar(), game::dump_stats(), durability_indicator(), Character::eat(), einkpc_download_memory_card(), iuse::einktabletpc(), emit_radio_signal(), final_info(), character_funcs::find_ammo_helper(), find_auto_consume(), find_food_heater(), Character::find_remote_fuel(), findBestGasDiscount(), ranged::fire_gun(), activity_handlers::fish_do_turn(), character_funcs::fmt_wielded_weapon(), food_info(), inventory::form_from_map(), Character::fun_for(), activity_handlers::game_do_turn(), character_funcs::get_book_fun_for(), activatable_inventory_preset::get_denial(), bionic_sterilize_preset::get_denial(), get_encumber_when_containing(), ranged::get_fastest_sight(), Character::get_fuel_available(), get_layer(), zone_manager::get_near_zone_type_for_item(), get_sizing(), ranged::get_str_draw_penalty(), getlight_emit(), give_item_to(), goes_bad(), gun_info(), iuse::gun_repair(), gunmod_info(), ranged::gunmode_checks_common(), ranged::gunmode_checks_weapon(), iuse::hand_crank(), ranged::handle_gun_damage(), Character::handle_melee_wear(), handle_problematic_pickup(), Character::has_enough_charges(), has_flag(), Character::has_item_with_flag(), Character::head_cloth_encumbrance(), iuse_transform::info(), inherit_flags(), npc_trading::init_buying(), init_memory_card_with_random_stuff(), target_ui::init_window_and_input(), monexamine::insert_battery(), is_ammo_belt(), is_armor(), is_corpse(), is_dangerous(), advanced_inventory_pane::is_filtered(), is_filthy(), is_firearm(), character_funcs::is_fun_to_read(), is_gunmod_compatible(), is_irremovable(), vehicle::is_perpetual_type(), is_pet_armor(), is_power_armor(), is_reloadable(), is_salvageable(), bionic_uninstall_preset::is_shown(), is_two_handed(), is_unarmed_weapon(), ma_requirements::is_valid_character(), ma_requirements::is_valid_weapon(), is_worn_only_with(), item(), Character::item_reload_cost(), mdeath::jabberwock(), layer_item(), magazine_info(), item_action_generator::map_actions_to_items(), Character::meets_stat_requirements(), Character::melee_attack(), melee_skill(), Character::melee_special_effects(), npc_ai::melee_value(), mine_activity(), Item_modifier::modify(), Character::modify_morale(), avatar_action::move(), game_menus::inv::multiwash(), Character::mutation_effect(), iexamine::nanofab(), needs_processing(), iuse::note_bionics(), on_wear(), on_wield(), iuse::pack_cbm(), Character::passive_power_gen(), monexamine::pet_menu(), avatar_action::plthrow(), iuse::poison(), item_category::priority_zone(), process_extinguish(), process_internal(), Character::process_items(), process_litcig(), process_tool(), process_UPS(), process_vehicle_items(), vehicle_part::properties_to_item(), mattack::pull_metal_weapon(), activity_handlers::pulp_do_turn(), item_reload_option::qty(), iuse::radio_mod(), iuse::radiocar(), iuse::radiocontrol(), rate_food(), rcdrive(), reach_range(), ready_to_revive(), reinforceable(), avatar_action::reload(), reload(), activity_handlers::reload_finish(), remove_ammo(), remove_radio_mod(), repair_item_actor::repair(), repaired_with(), game::revive_corpse(), iexamine::safe(), character_funcs::select_ammo(), set_relative_rot(), player_morale::set_worn(), sight_dispersion(), iexamine::sign(), smoker_load_food(), map::spawn_item(), activity_handlers::spellcasting_finish(), activity_handlers::start_fire_do_turn(), starting_clothes(), starting_inv(), ranged::str_draw_damage_modifier(), ranged::str_draw_dispersion_modifier(), ranged::str_draw_range_modifier(), ranged::throw_item(), tname(), tool_info(), iuse::toolmod_attach(), iuse::towel_common(), type_name(), Character::unarmed_attack(), units_remaining(), avatar_funcs::unload_item(), charger_tile::update_internal(), iuse_transform::use(), set_transform_iuse::use(), unpack_actor::use(), cast_spell_actor::use(), Character::use_charges(), iexamine::use_furn_fake_item(), avatar_action::use_item(), avatar_funcs::use_item(), vehicle::use_washing_machine(), npc::value(), volume(), martialart::weapon_valid(), npc::wear_if_wanted(), Character::wear_item(), iuse::weather_tool(), weight(), weather_effect::wet_player(), npc::will_accept_from_player(), and Character::will_eat().

◆ has_infinite_charges()

bool item::has_infinite_charges ( ) const

Definition at line 9990 of file item.cpp.

9991{
9992 return charges == INFINITE_CHARGES;
9993}

References charges, and INFINITE_CHARGES.

Referenced by display_name(), liquid_handler::get_liquid_target(), mod_charges(), and Character::will_eat().

◆ has_label()

bool item::has_label ( ) const

Returns true if item has "item_label" itemvar.

Definition at line 9976 of file item.cpp.

9977{
9978 return has_var( "item_label" );
9979}

References has_var().

Referenced by label().

◆ has_own_flag()

bool item::has_own_flag ( const std::string &  flag) const

Checks whether item itself has given flag (doesn't check item type or gunmods).

Essentially get_flags().count(f). Works faster than has_flag

Definition at line 5323 of file item.cpp.

5324{
5325 return item_tags.count( f );
5326}
size_type count(const T &t) const
Definition: flat_set.h:141

References cata::flat_set< T, Compare, Data >::count(), and item_tags.

Referenced by Character::can_eat(), Character::can_wear(), color_in_inventory(), final_info(), has_clothing_mod(), has_flag(), mod_last_rot_check(), on_drop(), tname(), update_clothing_mod_val(), and sew_advanced_actor::use().

◆ has_property()

bool item::has_property ( const std::string &  prop) const

Definition at line 5383 of file item.cpp.

5384{
5385 return type->properties.find( prop ) != type->properties.end();
5386}

References itype::properties, and type.

Referenced by iuse::capture_monster_act(), and ranged::throw_item().

◆ has_rotten_away()

bool item::has_rotten_away ( ) const

Whether the item has enough rot that it should get removed.

Regular shelf life perishable foods rot away completely at 2x shelf life. Corpses last 10 days

Returns
true if the item has enough rot to be removed, false otherwise.

Definition at line 8811 of file item.cpp.

8812{
8813 if( is_corpse() && !can_revive() ) {
8814 return get_rot() > 10_days;
8815 } else {
8816 return is_food() && get_relative_rot() > 2.0;
8817 }
8818}
time_duration get_rot() const
Definition: item.h:860

References can_revive(), get_relative_rot(), get_rot(), is_corpse(), and is_food().

Referenced by process_rot().

◆ has_technique()

bool item::has_technique ( const matec_id tech) const

Whether the item supports a specific martial art technique (either through its type, or through its individual techniques).

Definition at line 5464 of file item.cpp.

5465{
5466 return type->techniques.count( tech ) > 0 || techniques.count( tech ) > 0;
5467}

References techniques, itype::techniques, and type.

Referenced by blocking_ability(), effective_dps(), character_martial_arts::has_technique(), and mdeath::jabberwock().

◆ has_tools_to_continue()

bool item::has_tools_to_continue ( ) const

Definition at line 10135 of file item.cpp.

10136{
10137 assert( craft_data_ );
10138 return craft_data_->tools_to_continue;
10139}

References craft_data_.

◆ has_use()

bool item::has_use ( ) const

Returns true if the item has any use function.

Definition at line 7959 of file item.cpp.

7960{
7961 return type->has_use();
7962}
bool has_use() const
Definition: itype.cpp:141

References itype::has_use(), and type.

◆ has_var()

◆ ideal_ranged_dps()

double item::ideal_ranged_dps ( const Character who,
gun_mode mode 
) const

Definition at line 2073 of file npcmove.cpp.

2074{
2075 if( !is_gun() ) {
2076 return 0;
2077 }
2079 if( ammo_current() ) {
2080 itype_id ammo = ammo_current();
2081 gun_damage.add( ammo->ammo->damage );
2082 } else if( ammo_default() ) {
2083 itype_id ammo = ammo_default();
2084 gun_damage.add( ammo->ammo->damage );
2085 }
2086 float damage_factor = gun_damage.total_damage();
2087 damage_factor *= mode.qty;
2088
2089 int move_cost = ranged::time_to_attack( who, *this, item_location() );
2090 if( ammo_remaining() == 0 ) {
2091 int reload_cost = get_reload_time() + who.encumb( bp_hand_l ) + who.encumb( bp_hand_r );
2092 // HACK: Doesn't check how much ammo they'll actually get from the reload. Because we don't know.
2093 // DPS is less impacted the larger the magazine being swapped.
2094 reload_cost /= magazine_integral() ? 1 : ammo_capacity() / mode.qty;
2095 move_cost += reload_cost;
2096 }
2097 std::vector<ranged::aim_type> aim_types = ranged::get_aim_types( who, *this );
2098 auto regular = std::find_if( aim_types.begin(),
2099 aim_types.end(), []( ranged::aim_type at ) {
2100 return at.action == std::string( "AIMED_SHOT" );
2101 } );
2102 if( regular == aim_types.end() ) {
2103 debugmsg( "Could not find REGULAR aim type for gun %s", tname() );
2104 return 0;
2105 }
2106 move_cost += ranged::gun_engagement_moves( who, *this, ( *regular ).threshold );
2107
2108 double dps = damage_factor / ( move_cost / 100.0f );
2109
2110 return dps;
2111}
static int move_cost(const item &it, const tripoint &src, const tripoint &dest)
int qty
burst size for is_gun() firearms, or melee range for is_melee() weapons
Definition: gun_mode.h:21
A lightweight handle to an item independent of it's location Unlike a raw pointer can be (de-)seriali...
Definition: item_location.h:23
int get_reload_time() const
Returns the reload time of the gun.
Definition: item.cpp:6553
void regular(const queued_explosion &qe)
Definition: explosion.cpp:1466
int time_to_attack(const Character &p, const item &firing, const item_location loc)
Calculates time taken to fire gun.
Definition: ranged.cpp:1737
void add(const damage_instance &added_di)
Definition: damage.cpp:93

References damage_instance::add(), itype::ammo, ammo_capacity(), ammo_current(), ammo_default(), ammo_remaining(), bp_hand_l, bp_hand_r, debugmsg, dps(), Character::encumb(), ranged::get_aim_types(), get_reload_time(), gun_damage(), ranged::gun_engagement_moves(), is_gun(), magazine_integral(), move_cost(), gun_mode::qty, explosion_handler::explosion_funcs::regular(), ranged::time_to_attack(), tname(), and damage_instance::total_damage().

Referenced by npc::check_or_use_weapon_cbm(), and npc_ai::gun_value().

◆ in_container()

item item::in_container ( const itype_id container_type) const

Definition at line 849 of file item.cpp.

850{
851 if( !cont.is_null() ) {
852 item ret( cont, birthday() );
853 ret.put_in( *this );
854 if( made_of( LIQUID ) && ret.is_container() ) {
855 // Note: we can't use any of the normal container functions as they check the
856 // container being suitable (seals, watertight etc.)
857 ret.contents.back().charges = charges_per_volume( ret.get_container_capacity() );
858 }
859
860 ret.invlet = invlet;
861 return ret;
862 } else {
863 return *this;
864 }
865}
char invlet
Definition: item.h:2236

References birthday(), charges_per_volume(), invlet, string_id< T >::is_null(), LIQUID, made_of(), and cata::hash64_detail::ret.

Referenced by in_its_container().

◆ in_its_container()

item item::in_its_container ( ) const

Returns this item into its default container.

If it does not have a default container, returns this. It's intended to be used like

newitem = newitem.in_its_container();

Definition at line 844 of file item.cpp.

845{
846 return in_container( type->default_container.value_or( itype_id::NULL_ID() ) );
847}
item in_container(const itype_id &container_type) const
Definition: item.cpp:849
std::optional< itype_id > default_container
Definition: itype.h:880

References itype::default_container, in_container(), string_id< itype >::NULL_ID(), and type.

Referenced by defense_game::caravan(), crafting::complete_disassemble(), Single_item_creator::create_single(), map::spawn_an_item(), starting_inv(), and debug_menu::wishitem().

◆ inc_damage() [1/2]

bool item::inc_damage ( )

same as other inc_damage, but uses DT_NULL as damage type.

Definition at line 6283 of file item.cpp.

6284{
6285 return inc_damage( DT_NULL );
6286}
bool inc_damage()
same as other inc_damage, but uses DT_NULL as damage type.
Definition: item.cpp:6283

References DT_NULL, and inc_damage().

Referenced by inc_damage(), and process_blackpowder_fouling().

◆ inc_damage() [2/2]

bool item::inc_damage ( damage_type  dt)

Increment item damage by itype::damage_scale constrained by max_damage.

Parameters
dttype of damage which may be passed to on_damage callback
Returns
whether item should be destroyed

Definition at line 6278 of file item.cpp.

6279{
6280 return mod_damage( itype::damage_scale, dt );
6281}
bool mod_damage(int qty, damage_type dt)
Apply damage to const itemrained by min_damage and max_damage.
Definition: item.cpp:6251
static constexpr int damage_scale
Definition: itype.h:976

References itype::damage_scale, and mod_damage().

Referenced by iuse::blood_draw(), damage_item(), iuse::firecracker_pack_act(), activity_handlers::gunmod_add_finish(), ranged::handle_gun_damage(), Character::handle_melee_wear(), activity_handlers::lockpicking_finish(), and vehicle::operate_scoop().

◆ info() [1/4]

std::vector< iteminfo > item::info ( ) const

Return all the information about the item and its type as a vector.

This includes the different properties of the itype (if they are visible to the player).

Parameters
partscontrols which parts of the iteminfo to return.
batchThe batch crafting number to multiply data by
Returns
The properties (encapsulated into iteminfo) are added to this vector, the vector can be used to compare them to properties of another item.

Definition at line 3991 of file item.cpp.

3992{
3994}
static const iteminfo_query no_conditions

References info(), iteminfo_query::no_conditions, and TEMP_NORMAL.

Referenced by advanced_inventory::action_examine(), ammo_info(), animal_armor_info(), armor_fit_info(), armor_info(), armor_protection_info(), basic_info(), battery_info(), bionic_info(), book_info(), combat_info(), game_menus::inv::compare(), component_info(), container_info(), contents_info(), disassembly_info(), final_info(), food_info(), gun_info(), gunmod_info(), info(), info_string(), game::list_items(), magazine_info(), med_info(), qualities_info(), wish_item_callback::refresh(), repair_info(), examine_item_menu::run(), trading_window::show_item_data(), and tool_info().

◆ info() [2/4]

std::vector< iteminfo > item::info ( const iteminfo_query parts,
int  batch,
temperature_flag  temperature 
) const

Definition at line 4006 of file item.cpp.

4008{
4009 const bool debug = g != nullptr && debug_mode;
4010
4011 // TODO: Use reference properly
4012 const iteminfo_query *parts = &parts_ref;
4013 std::vector<iteminfo> info;
4014
4015 if( !is_null() ) {
4016 basic_info( info, parts, batch, debug );
4017 }
4018
4019 const item *med_item = nullptr;
4020 if( is_medication() ) {
4021 med_item = this;
4022 } else if( is_med_container() ) {
4023 med_item = &contents.front();
4024 }
4025 if( med_item != nullptr ) {
4026 med_info( med_item, info, parts, batch, debug );
4027 }
4028
4029 if( const item *food_item = get_food() ) {
4030 food_info( food_item, info, parts, batch, debug, temperature );
4031 }
4032
4033 container_info( info, parts, batch, debug );
4034 contents_info( info, parts, batch, debug );
4035 combat_info( info, parts, batch, debug );
4036
4037 magazine_info( info, parts, batch, debug );
4038 ammo_info( info, parts, batch, debug );
4039
4040 const item *gun = nullptr;
4041 if( is_gun() ) {
4042 gun = this;
4043 const gun_mode aux = gun_current_mode();
4044 // if we have an active auxiliary gunmod display stats for this instead
4045 if( aux && aux->is_gunmod() && aux->is_gun() &&
4047 gun = &*aux;
4048 info.emplace_back( "DESCRIPTION",
4049 string_format( _( "Stats of the active <info>gunmod (%s)</info> "
4050 "are shown." ), gun->tname() ) );
4051 }
4052 }
4053 if( gun != nullptr ) {
4054 gun_info( gun, info, parts, batch, debug );
4055 }
4056
4057 gunmod_info( info, parts, batch, debug );
4058 armor_info( info, parts, batch, debug );
4059 animal_armor_info( info, parts, batch, debug );
4060 book_info( info, parts, batch, debug );
4061 battery_info( info, parts, batch, debug );
4062 tool_info( info, parts, batch, debug );
4063 component_info( info, parts, batch, debug );
4064 qualities_info( info, parts, batch, debug );
4065
4066 // Uses for item (bandaging quality, holster capacity, grenade activation)
4068 for( const std::pair<const std::string, use_function> &method : type->use_methods ) {
4070 method.second.dump_info( *this, info );
4071 }
4072 }
4073
4074 repair_info( info, parts, batch, debug );
4075 disassembly_info( info, parts, batch, debug );
4076
4077 final_info( info, parts_ref, batch, debug );
4078
4079 if( !info.empty() && info.back().sName == "--" ) {
4080 info.pop_back();
4081 }
4082
4083 return info;
4084}
void gunmod_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2383
gun_mode gun_current_mode() const
Get the current mode for this gun (or an invalid mode if item is not a gun)
Definition: item.cpp:7914
void contents_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3563
void animal_armor_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2735
void med_info(const item *med_item, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:1644
void disassembly_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3194
void combat_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3418
bool is_med_container() const
Definition: item.cpp:6640
void qualities_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3248
void gun_info(const item *mod, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2020
void component_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3149
void repair_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3173
void magazine_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:1884
void food_info(const item *food_item, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug, temperature_flag temperature) const
Definition: item.cpp:1673
void armor_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2552
void battery_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3082
void ammo_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:1907
void basic_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:1461
void final_info(std::vector< iteminfo > &info, const iteminfo_query &parts, int batch, bool debug) const
Definition: item.cpp:3646
void book_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2917
void tool_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3101
void container_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3054
@ DESCRIPTION_AUX_GUNMOD_HEADER

References _, ammo_info(), animal_armor_info(), armor_info(), basic_info(), battery_info(), book_info(), combat_info(), component_info(), container_info(), contents, contents_info(), debug, debug_mode, DESCRIPTION_AUX_GUNMOD_HEADER, DESCRIPTION_USE_METHODS, disassembly_info(), final_info(), food_info(), item_contents::front(), g, get_food(), gun_current_mode(), gun_info(), gunmod_info(), info(), insert_separation_line(), is_gun(), is_gunmod(), is_med_container(), is_medication(), is_null(), magazine_info(), med_info(), qualities_info(), repair_info(), string_format(), iteminfo_query::test(), tname(), tool_info(), type, and itype::use_methods.

◆ info() [3/4]

std::vector< iteminfo > item::info ( int  batch) const

Definition at line 3996 of file item.cpp.

References info(), iteminfo_query::no_conditions, and TEMP_NORMAL.

◆ info() [4/4]

std::vector< iteminfo > item::info ( temperature_flag  temperature) const

Definition at line 4001 of file item.cpp.

4002{
4003 return info( iteminfo_query::all, 1, temperature );
4004}
static const iteminfo_query all

References iteminfo_query::all, and info().

◆ info_string() [1/2]

std::string item::info_string ( ) const

As info, but as a string rather than a vector of properties.

Definition at line 4086 of file item.cpp.

4087{
4088 return info_string( iteminfo_query::all, 1 );
4089}

References iteminfo_query::all, and info_string().

Referenced by battery_info(), colorized_item_description(), draw_caravan_items(), and info_string().

◆ info_string() [2/2]

std::string item::info_string ( const iteminfo_query parts,
int  batch = 1,
temperature_flag  temperature = temperature_flag::TEMP_NORMAL 
) const

Definition at line 4091 of file item.cpp.

4093{
4094 std::vector<iteminfo> item_info = info( parts, batch, temperature );
4095 return format_item_info( item_info, {} );
4096}
std::string format_item_info(const std::vector< iteminfo > &item_display, const std::vector< iteminfo > &item_compare)
Definition: output.cpp:854

References format_item_info(), and info().

◆ inherit_flags() [1/2]

void item::inherit_flags ( const item parent,
const recipe making 
)

Inherit applicable flags from the given parent item.

Parameters
parentItem to inherit from

Definition at line 984 of file crafting.cpp.

985{
986 // default behavior is to resize the clothing, which happens elsewhere
987 if( making.has_flag( flag_NO_RESIZE ) ) {
988 //If item is crafted from poor-fit components, the result is poorly fitted too
989 if( parent.has_flag( flag_VARSIZE ) ) {
991 }
992 //If item is crafted from perfect-fit components, the result is perfectly fitted too
993 if( parent.has_flag( flag_FIT ) ) {
995 }
996 }
997 for( const std::string &f : parent.item_tags ) {
998 if( json_flag::get( f ).craft_inherit() ) {
999 set_flag( f );
1000 }
1001 }
1002 for( const std::string &f : parent.type->get_flags() ) {
1003 if( json_flag::get( f ).craft_inherit() ) {
1004 set_flag( f );
1005 }
1006 }
1007 if( parent.has_flag( flag_HIDDEN_POISON ) ) {
1008 poison = parent.poison;
1009 }
1010}
int poison
Definition: item.h:2204
bool has_flag(const std::string &flag_name) const
Definition: recipe.cpp:95
static const std::string flag_NO_RESIZE("NO_RESIZE")
static const std::string flag_HIDDEN_POISON("HIDDEN_POISON")
static const std::string flag_FIT("FIT")
static const std::string flag_VARSIZE("VARSIZE")

References flag_FIT(), flag_HIDDEN_POISON(), flag_NO_RESIZE(), flag_VARSIZE(), json_flag::get(), itype::get_flags(), has_flag(), recipe::has_flag(), item_tags, poison, set_flag(), type, and unset_flag().

Referenced by complete_craft(), and inherit_flags().

◆ inherit_flags() [2/2]

void item::inherit_flags ( const std::list< item > &  parents,
const recipe making 
)

Inherit applicable flags from the given list of parent items.

Parameters
parentsItems to inherit from

Definition at line 1012 of file crafting.cpp.

1013{
1014 for( const item &parent : parents ) {
1015 inherit_flags( parent, making );
1016 }
1017}
void inherit_flags(const item &parent, const recipe &making)
Inherit applicable flags from the given parent item.
Definition: crafting.cpp:984
std::vector< item * > parents(const item &it)
Returns vector of parent containers (if any) starting with the innermost.
Definition: visitable.cpp:73

References inherit_flags(), and visitable< item >::parents().

◆ io()

template<typename Archive >
void item::io ( Archive &  archive)

Definition at line 2188 of file savegame_json.cpp.

2189{
2190
2191 itype_id orig; // original ID as loaded from JSON
2192 const auto load_type = [&]( const std::string & id ) {
2193 orig = itype_id( id );
2194 convert( item_controller->migrate_id( orig ) );
2195 };
2196
2197 const auto load_curammo = [this]( const std::string & id ) {
2198 curammo = &*item_controller->migrate_id( itype_id( id ) );
2199 };
2200 const auto load_corpse = [this]( const std::string & id ) {
2201 if( itype_id( id ).is_null() ) {
2202 // backwards compatibility, nullptr should not be stored at all
2203 corpse = nullptr;
2204 } else {
2205 corpse = &mtype_id( id ).obj();
2206 }
2207 };
2208 archive.template io<const itype>( "typeid", type, load_type, []( const itype & i ) {
2209 return i.get_id().str();
2210 }, io::required_tag() );
2211
2212 // normalize legacy saves to always have charges >= 0
2213 archive.io( "charges", charges, 0 );
2214 charges = std::max( charges, 0 );
2215
2216 archive.io( "energy", energy, 0_J );
2217
2218 archive.io( "burnt", burnt, 0 );
2219 archive.io( "poison", poison, 0 );
2220 archive.io( "frequency", frequency, 0 );
2221 archive.io( "snip_id", snip_id, snippet_id::NULL_ID() );
2222 // NB! field is named `irridation` in legacy files
2223 archive.io( "irridation", irradiation, 0 );
2224 archive.io( "bday", bday, calendar::start_of_cataclysm );
2225 archive.io( "mission_id", mission_id, -1 );
2226 archive.io( "player_id", player_id, -1 );
2227 archive.io( "item_vars", item_vars, io::empty_default_tag() );
2228 // TODO: change default to empty string
2229 archive.io( "name", corpse_name, std::string() );
2230 archive.io( "owner", owner, owner.NULL_ID() );
2231 archive.io( "old_owner", old_owner, old_owner.NULL_ID() );
2232 archive.io( "invlet", invlet, '\0' );
2233 archive.io( "damaged", damage_, 0 );
2234 archive.io( "active", active, false );
2235 archive.io( "is_favorite", is_favorite, false );
2236 archive.io( "item_counter", item_counter, static_cast<decltype( item_counter )>( 0 ) );
2237 archive.io( "rot", rot, 0_turns );
2238 archive.io( "last_rot_check", last_rot_check, calendar::start_of_cataclysm );
2239 archive.io( "techniques", techniques, io::empty_default_tag() );
2240 archive.io( "faults", faults, io::empty_default_tag() );
2241 archive.io( "item_tags", item_tags, io::empty_default_tag() );
2242 archive.io( "components", components, io::empty_default_tag() );
2243 archive.io( "recipe_charges", recipe_charges, 1 );
2244 archive.template io<const itype>( "curammo", curammo, load_curammo,
2245 []( const itype & i ) {
2246 return i.get_id().str();
2247 } );
2248 archive.template io<const mtype>( "corpse", corpse, load_corpse,
2249 []( const mtype & i ) {
2250 return i.id.str();
2251 } );
2252 archive.io( "craft_data", craft_data_, decltype( craft_data_ )() );
2253 archive.io( "light", light.luminance, nolight.luminance );
2254 archive.io( "light_width", light.width, nolight.width );
2255 archive.io( "light_dir", light.direction, nolight.direction );
2256
2257 static const cata::value_ptr<relic> null_relic_ptr = nullptr;
2258 archive.io( "relic_data", relic_data, null_relic_ptr );
2259
2260 archive.io( "drop_token", drop_token, decltype( drop_token )() );
2261
2262 item_controller->migrate_item( orig, *this );
2263
2264 if( !Archive::is_input::value ) {
2265 return;
2266 }
2267 /* Loading has finished, following code is to ensure consistency and fixes bugs in saves. */
2268
2270
2271 double float_damage = 0;
2272 if( archive.read( "damage", float_damage ) ) {
2273 damage_ = std::min( std::max( min_damage(),
2274 static_cast<int>( float_damage * itype::damage_scale ) ),
2275 max_damage() );
2276 }
2277
2278 int note = 0;
2279 const bool note_read = archive.read( "note", note );
2280
2281 // Old saves used to only contain one of those values (stored under "poison"), it would be
2282 // loaded into a union of those members. Now they are separate members and must be set separately.
2283 if( poison != 0 && note == 0 && !type->snippet_category.empty() ) {
2284 std::swap( note, poison );
2285 }
2286 if( poison != 0 && frequency == 0 && ( typeId() == itype_radio_on || typeId() == itype_radio ) ) {
2288 }
2289 if( poison != 0 && irradiation == 0 && typeId() == itype_rad_badge ) {
2291 }
2292
2293 // erase all invalid flags (not defined in flags.json), display warning about invalid flags
2294 erase_if( item_tags, [&]( const std::string & f ) {
2295 if( !json_flag::get( f ).id.is_valid() ) {
2296 debugmsg( "item of type '%s' was loaded with undefined flag '%s'.", typeId().c_str(), f );
2297 return true;
2298 } else {
2299 return false;
2300 }
2301 } );
2302
2303 if( note_read ) {
2305 } else {
2306 std::optional<std::string> snip;
2307 if( archive.read( "snippet_id", snip ) && snip ) {
2308 snip_id = snippet_id( snip.value() );
2309 }
2310 }
2311
2312 // Compatibility for item type changes: for example soap changed from being a generic item
2313 // (item::charges -1 or 0 or anything else) to comestible (and thereby counted by charges),
2314 // old saves still have invalid charges, this fixes the charges value to the default charges.
2315 if( count_by_charges() && charges <= 0 ) {
2317 }
2318 if( is_food() ) {
2319 active = true;
2320 }
2321 if( !active && item_tags.count( "WET" ) > 0 ) {
2322 // Some wet items from legacy saves may be inactive
2323 active = true;
2324 }
2325 std::string mode;
2326 if( archive.read( "mode", mode ) ) {
2327 // only for backward compatibility (nowadays mode is stored in item_vars)
2328 gun_set_mode( gun_mode_id( mode ) );
2329 }
2330
2331 // Books without any chapters don't need to store a remaining-chapters
2332 // counter, it will always be 0 and it prevents proper stacking.
2333 if( get_chapters() == 0 ) {
2334 for( auto it = item_vars.begin(); it != item_vars.end(); ) {
2335 if( it->first.compare( 0, 19, "remaining-chapters-" ) == 0 ) {
2336 item_vars.erase( it++ );
2337 } else {
2338 ++it;
2339 }
2340 }
2341 }
2342
2343 // Remove stored translated gerund in favor of storing the inscription tool type
2344 item_vars.erase( "item_label_type" );
2345 item_vars.erase( "item_note_type" );
2346
2347 // Activate corpses from old saves
2348 if( is_corpse() && !active ) {
2349 active = true;
2350 }
2351
2352 if( charges != 0 && !type->can_have_charges() ) {
2353 // Types that are known to have charges, but should not have them.
2354 // We fix it here, but it's expected from bugged saves and does not require a message.
2355 if( charge_removal_blacklist::get().count( type->get_id() ) == 0 ) {
2356 debugmsg( "Item %s was loaded with charges, but can not have any!", type->get_id() );
2357 }
2358 charges = 0;
2359 }
2360
2361 // Relic check. Kinda late, but that's how relics have to be
2362 if( relic_data ) {
2363 relic_data->check();
2364 }
2365}
bool erase_if(Col &set, Pred predicate)
Erases elements from a set that match given predicate function.
Definition: cata_utility.h:237
int player_id
Definition: item.h:2210
int mission_id
Definition: item.h:2209
int frequency
Definition: item.h:2205
int recipe_charges
Definition: item.h:2202
snippet_id migrate_hash_to_id(int hash)
Used only for legacy compatibility.
light_emission nolight
Definition: item.cpp:315
void swap(colony< element_type, element_allocator_type, element_skipfield_type > &a, colony< element_type, element_allocator_type, element_skipfield_type > &b) COLONY_NOEXCEPT_SWAP(element_allocator_type)
Swaps colony A's contents with that of colony B.
Definition: colony.h:3496
const std::set< itype_id > & get()
static void load_legacy_craft_data(io::JsonObjectInputArchive &archive, T &value)
static const itype_id itype_radio("radio")
static const itype_id itype_radio_on("radio_on")
static const itype_id itype_rad_badge("rad_badge")
Tag that indicates the value of the io is some kind of container and its default value is to be empty...
Definition: cata_io.h:105
Tag that indicates the value is required and must exists in the JSON data.
Definition: cata_io.h:110
bool can_have_charges() const
Definition: itype.cpp:214
mtype_id id
Definition: mtype.h:240
string_id< translation > snippet_id
Definition: type_id.h:205

References active, bday, burnt, itype::can_have_charges(), charges, components, convert(), corpse, corpse_name, count(), cata::flat_set< T, Compare, Data >::count(), count_by_charges(), craft_data_, curammo, damage_, itype::damage_scale, debugmsg, light_emission::direction, energy, erase_if(), faults, frequency, charge_removal_blacklist::get(), json_flag::get(), get_chapters(), itype::get_id(), gun_set_mode(), base_camps::id, itype::id, invlet, irradiation, is_corpse(), is_favorite, is_food(), item(), item_controller, item_counter, item_tags, item_vars, itype_id, itype_rad_badge, itype_radio, itype_radio_on, last_rot_check, light, load_legacy_craft_data(), light_emission::luminance, max_damage(), snippet_library::migrate_hash_to_id(), min_damage(), mission_id, mtype_id, nolight, string_id< translation >::NULL_ID(), string_id< T >::NULL_ID(), old_owner, owner, player_id, poison, recipe_charges, relic_data, snip_id, SNIPPET, itype::snippet_category, calendar::start_of_cataclysm, string_id< T >::str(), cata::swap(), techniques, type, typeId(), and light_emission::width.

Referenced by deserialize(), and serialize().

◆ is_ammo()

◆ is_ammo_belt()

bool item::is_ammo_belt ( ) const

Definition at line 6592 of file item.cpp.

6593{
6594 return is_magazine() && has_flag( flag_MAG_BELT );
6595}
static const std::string flag_MAG_BELT("MAG_BELT")

References flag_MAG_BELT(), has_flag(), and is_magazine().

Referenced by Character::can_reload(), item_reload_option::item_reload_option(), avatar_action::reload(), reload(), and avatar_funcs::unload_item().

◆ is_ammo_container()

◆ is_armor()

◆ is_artifact()

bool item::is_artifact ( ) const

Definition at line 6993 of file item.cpp.

6994{
6995 return !!type->artifact;
6996}

References itype::artifact, and type.

Referenced by game::add_artifact_dreams(), iuse::artifact(), needs_processing(), and process_artifact().

◆ is_bandolier()

bool item::is_bandolier ( ) const

◆ is_battery()

bool item::is_battery ( ) const

Definition at line 6587 of file item.cpp.

6588{
6589 return !!type->battery;
6590}

References itype::battery, and type.

Referenced by battery_info(), display_name(), energy_remaining(), and mod_energy().

◆ is_bionic()

◆ is_book()

◆ is_brewable()

bool item::is_brewable ( ) const

Definition at line 6628 of file item.cpp.

6629{
6630 return !!type->brewable;
6631}

References itype::brewable, and type.

Referenced by brewing_results(), brewing_time(), final_info(), iexamine::fvat_empty(), and iexamine::fvat_full().

◆ is_bucket()

bool item::is_bucket ( ) const

Definition at line 6759 of file item.cpp.

6760{
6761 // That "preserves" part is a hack:
6762 // Currently all non-empty cans are effectively sealed at all times
6763 // Making them buckets would cause weirdness
6764 return type->container &&
6765 type->container->watertight &&
6766 !type->container->seals &&
6767 !type->container->unseals_into;
6768}

References itype::container, and type.

Referenced by can_unload_liquid(), get_remaining_capacity_for_liquid(), is_bucket_nonempty(), is_container_eligible_for_crafting(), is_funnel_container(), pick_one_up(), and iexamine::tree_maple_tapped().

◆ is_bucket_nonempty()

bool item::is_bucket_nonempty ( ) const

◆ is_comestible()

◆ is_container()

◆ is_container_empty()

◆ is_container_full()

bool item::is_container_full ( bool  allow_bucket = false) const

Whether this item has no more free capacity for its current content.

Parameters
allow_bucketAllow filling non-sealable containers

Definition at line 6867 of file item.cpp.

6868{
6869 if( is_container_empty() ) {
6870 return false;
6871 }
6872 return get_remaining_capacity_for_liquid( contents.front(), allow_bucket ) == 0;
6873}

References contents, item_contents::front(), get_remaining_capacity_for_liquid(), and is_container_empty().

Referenced by is_container_eligible_for_crafting(), is_reloadable_helper(), and avatar_action::reload().

◆ is_corpse()

bool item::is_corpse ( ) const

Whether this is a corpse item.

Corpses always have valid monster type (corpse) associated (get_mtype return a non-null pointer) and have been created with make_corpse.

Definition at line 6645 of file item.cpp.

6646{
6647 return corpse != nullptr && has_flag( flag_CORPSE );
6648}

References corpse, flag_CORPSE(), and has_flag().

Referenced by base_volume(), burn(), activity_handlers::butcher_finish(), calc_rot(), can_revive(), color(), color_in_inventory(), component_info(), zone_manager::get_near_zone_type_for_item(), get_shelf_life(), goes_bad(), has_rotten_away(), io(), made_of(), on_damage(), process_internal(), map::process_items_in_vehicle(), processing_speed(), game::revive_corpse(), tname(), volume(), and weight().

◆ is_craft()

◆ is_dangerous()

bool item::is_dangerous ( ) const

Definition at line 9830 of file item.cpp.

9831{
9832 if( has_flag( flag_DANGEROUS ) ) {
9833 return true;
9834 }
9835
9836 // Note: Item should be dangerous regardless of what type of a container is it
9837 // Visitable interface would skip some options
9838 for( const item *it : contents.all_items_top() ) {
9839 if( it->is_dangerous() ) {
9840 return true;
9841 }
9842 }
9843 return false;
9844}
static const std::string flag_DANGEROUS("DANGEROUS")

References item_contents::all_items_top(), contents, flag_DANGEROUS(), and has_flag().

Referenced by give_item_to(), and npc::value().

◆ is_deployable()

bool item::is_deployable ( ) const

Definition at line 6978 of file item.cpp.

6979{
6980 return type->can_use( "deploy_furn" );
6981}

References itype::can_use(), and type.

Referenced by Character::invoke_item().

◆ is_emissive()

bool item::is_emissive ( ) const

Whether the item emits any light at all.

Definition at line 6973 of file item.cpp.

6974{
6975 return light.luminance > 0 || type->light_emission > 0;
6976}

References light, itype::light_emission, light_emission::luminance, and type.

Referenced by submap::load(), map::update_lum(), submap::update_lum_add(), and submap::update_lum_rem().

◆ is_engine()

bool item::is_engine ( ) const

Definition at line 6775 of file item.cpp.

6776{
6777 return !!type->engine;
6778}

References itype::engine, and type.

Referenced by is_faulty(), and tname().

◆ is_faulty()

bool item::is_faulty ( ) const

Definition at line 6795 of file item.cpp.

6796{
6797 return is_engine() ? !faults.empty() : false;
6798}
bool is_engine() const
Definition: item.cpp:6775

References faults, and is_engine().

Referenced by clear_faults(), and vehicle_part::name().

◆ is_filthy()

bool item::is_filthy ( ) const

Marks the item as filthy, so characters with squeamish trait can't wear it.

Definition at line 10010 of file item.cpp.

10011{
10012 return has_flag( flag_FILTHY ) && ( get_option<bool>( "FILTHY_MORALE" ) ||
10014}
static const std::string flag_FILTHY("FILTHY")
static const trait_id trait_SQUEAMISH("SQUEAMISH")

References flag_FILTHY(), get_avatar(), has_flag(), Character::has_trait(), and trait_SQUEAMISH.

Referenced by Character::can_wear(), color_in_inventory(), crafting::complete_disassemble(), salvage_actor::cut_up(), repair_item_actor::handle_components(), item_category::priority_zone(), activity_handlers::reload_finish(), tname(), avatar_funcs::unload_item(), and heal_actor::use().

◆ is_firearm()

bool item::is_firearm ( ) const

Does it require gunsmithing tools to repair.

Definition at line 6547 of file item.cpp.

6548{
6549 static const std::string primitive_flag( "PRIMITIVE_RANGED_WEAPON" );
6550 return is_gun() && !has_flag( primitive_flag );
6551}

References has_flag(), and is_gun().

Referenced by repair_item_actor::can_repair_target(), iuse::gun_repair(), and repair_inventory_preset::is_shown().

◆ is_food()

◆ is_food_container()

bool item::is_food_container ( ) const

◆ is_fresh()

bool item::is_fresh ( ) const
inline

an item is fresh if it is capable of rotting but still has a long shelf life remaining

Definition at line 839 of file item.h.

839 {
840 return goes_bad() && get_relative_rot() < 0.1;
841 }

Referenced by comestible_inventory_preset::get_freshness(), get_freshness_description(), and tname().

◆ is_fuel()

bool item::is_fuel ( ) const

Definition at line 6785 of file item.cpp.

6786{
6787 return !!type->fuel;
6788}

References itype::fuel, and type.

Referenced by Character::can_fuel_bionic_with(), vehicle_part::consume_energy(), fuel_energy(), fuel_pump_terrain(), and has_explosion_data().

◆ is_funnel_container()

bool item::is_funnel_container ( units::volume bigger_than) const

Funnel related functions.

See weather.cpp for their usage.

Definition at line 6953 of file item.cpp.

6954{
6955 if( !is_bucket() && !is_watertight_container() ) {
6956 return false;
6957 }
6958 // TODO: consider linking funnel to item or -making- it an active item
6959 if( get_container_capacity() <= bigger_than ) {
6960 return false; // skip contents check, performance
6961 }
6962 if(
6963 contents.empty() ||
6967 bigger_than = get_container_capacity();
6968 return true;
6969 }
6970 return false;
6971}
bool is_watertight_container() const
Whether this is a container which can be used to store liquids.
Definition: item.cpp:6749
static const itype_id itype_water_acid_weak("water_acid_weak")
static const itype_id itype_water_acid("water_acid")
static const itype_id itype_water("water")

References contents, item_contents::empty(), item_contents::front(), get_container_capacity(), is_bucket(), is_watertight_container(), itype_water, itype_water_acid, itype_water_acid_weak, and typeId().

◆ is_going_bad()

bool item::is_going_bad ( ) const
inline

an item is about to become rotten when shelf life has nearly elapsed

Definition at line 844 of file item.h.

844 {
845 return get_relative_rot() > 0.9;
846 }

Referenced by get_freshness_description(), comestible_inventory_preset::get_time_left_rounded(), and tname().

◆ is_gun()

bool item::is_gun ( ) const

Can this item be used to perform a ranged attack?

See also
item::is_melee()
Note
an item can be both a gun and melee weapon concurrently

Definition at line 6542 of file item.cpp.

6543{
6544 return !!type->gun;
6545}

References itype::gun, and type.

Referenced by vehicle::add_item(), ranged::aim_per_move(), allow_crafting_component(), ammo_capacity(), ammo_consume(), character_funcs::ammo_count_for(), ammo_data(), ammo_effects(), ammo_info(), ammo_remaining(), ammo_required(), ammo_set(), ammo_sort_name(), ammo_types(), ammo_unset(), npc_ai::best_mode_for_range(), can_fire_turret(), avatar_action::can_fire_weapon(), saw_barrel_actor::can_use_on(), saw_stock_actor::can_use_on(), defense_game::caravan(), casings_handle(), npc::character_danger(), npc::check_or_use_weapon_cbm(), color_in_inventory(), npc::confident_shoot_range(), contents_info(), contextualize_skill(), damage_melee(), display_name(), durability_indicator(), final_info(), character_funcs::find_ammo_helper(), character_funcs::find_reloadables(), fire(), ranged::fire_gun(), avatar_action::fire_wielded_weapon(), character_funcs::fmt_wielded_weapon(), npc::form_opinion(), ranged::get_aim_types(), get_covered_body_parts(), get_encumber_when_containing(), get_free_mod_locations(), ranged::get_most_accurate_sight(), get_reload_time(), give_item_to(), gun_all_modes(), gun_cycle_mode(), gun_damage(), gun_dispersion(), gun_get_mode(), gun_get_mode_id(), gun_noise(), gun_range(), gun_recoil(), gun_set_mode(), gun_skill(), gunmod_info(), game::handle_action(), ranged::handle_gun_damage(), has_flag(), Character::i_add(), ideal_ranged_dps(), info(), character_effects::intimidation(), is_firearm(), is_gunmod_compatible(), is_reloadable(), gunmod_inventory_preset::is_shown(), saw_barrel_inventory_preset::is_shown(), saw_stock_inventory_preset::is_shown(), vehicle_part::is_turret(), Character::item_reload_cost(), Character::item_store_cost(), magazine_compatible(), magazine_default(), magazine_integral(), Item_modifier::modify(), item_reload_option::moves(), Character::on_dodge(), on_wield(), parse_tags(), tutorial_game::post_action(), Character::power_rating(), reach_range(), activity_handlers::reload_finish(), remove_ammo(), item_funcs::shots_remaining(), sight_dispersion(), starting_inv(), tname(), game::try_get_right_click_action(), character_funcs::try_wield_contents(), npc::value(), visit_internal(), volume(), weapon_inventory_preset::weapon_inventory_preset(), weight(), and npc::wield_better_weapon().

◆ is_gunmod()

◆ is_gunmod_compatible()

ret_val< bool > item::is_gunmod_compatible ( const item mod) const

Definition at line 7776 of file item.cpp.

7777{
7778 if( !mod.is_gunmod() ) {
7779 debugmsg( "Tried checking compatibility of non-gunmod" );
7781 }
7782 const islot_gunmod &g_mod = *mod.type->gunmod;
7783
7784 if( !is_gun() ) {
7785 return ret_val<bool>::make_failure( _( "isn't a weapon" ) );
7786
7787 } else if( is_gunmod() ) {
7788 return ret_val<bool>::make_failure( _( "is a gunmod and cannot be modded" ) );
7789
7790 } else if( gunmod_find( mod.typeId() ) ) {
7791 return ret_val<bool>::make_failure( _( "already has a %s" ), mod.tname( 1 ) );
7792
7793 } else if( !get_mod_locations().count( g_mod.location ) ) {
7794 return ret_val<bool>::make_failure( _( "doesn't have a slot for this mod" ) );
7795
7796 } else if( get_free_mod_locations( g_mod.location ) <= 0 ) {
7797 return ret_val<bool>::make_failure( _( "doesn't have enough room for another %s mod" ),
7798 mod.type->gunmod->location.name() );
7799
7800 } else if( !g_mod.usable.empty() || !g_mod.usable_category.empty() ) {
7801 bool usable = g_mod.usable.count( this->typeId() );
7802 for( const std::unordered_set<weapon_category_id> &mod_cat : g_mod.usable_category ) {
7803 if( usable ) {
7804 break;
7805 }
7806 if( std::all_of( mod_cat.begin(), mod_cat.end(), [this]( const weapon_category_id & wcid ) {
7807 return this->type->weapon_category.count( wcid );
7808 } ) ) {
7809 usable = true;
7810 }
7811 }
7812 if( !usable ) {
7813 return ret_val<bool>::make_failure( _( "cannot have a %s" ), mod.tname() );
7814 }
7815
7816 } else if( g_mod.location.str() == "underbarrel" &&
7818 return ret_val<bool>::make_failure( _( "can only accept small mods on that slot" ) );
7819
7820 } else if( !mod.type->mod->acceptable_ammo.empty() ) {
7821 bool compat_ammo = false;
7822 for( const ammotype &at : mod.type->mod->acceptable_ammo ) {
7823 if( ammo_types( false ).count( at ) ) {
7824 compat_ammo = true;
7825 }
7826 }
7827 if( !compat_ammo ) {
7829 _( "%1$s cannot be used on item with no compatible ammo types" ), mod.tname( 1 ) );
7830 }
7831 } else if( mod.typeId() == itype_waterproof_gunmod && has_flag( flag_WATERPROOF_GUN ) ) {
7832 return ret_val<bool>::make_failure( _( "is already waterproof" ) );
7833
7834 } else if( mod.typeId() == itype_tuned_mechanism && has_flag( flag_NEVER_JAMS ) ) {
7835 return ret_val<bool>::make_failure( _( "is already eminently reliable" ) );
7836
7837 } else if( mod.typeId() == itype_brass_catcher && has_flag( flag_RELOAD_EJECT ) ) {
7838 return ret_val<bool>::make_failure( _( "cannot have a brass catcher" ) );
7839
7840 } else if( ( !mod.type->mod->ammo_modifier.empty() || !mod.type->mod->magazine_adaptor.empty() )
7841 && ( ammo_remaining() > 0 || magazine_current() ) ) {
7842 return ret_val<bool>::make_failure( _( "must be unloaded before installing this mod" ) );
7843 }
7844
7845 for( const gunmod_location &slot : mod.type->gunmod->blacklist_mod ) {
7846 if( get_mod_locations().count( slot ) ) {
7847 return ret_val<bool>::make_failure( _( "cannot be installed on a weapon with \"%s\"" ),
7848 slot.name() );
7849 }
7850 }
7851
7853}
std::string name() const
Returns the translated name.
Definition: itype.cpp:15
std::string str() const
Returns the location id.
Definition: itype.h:85
static ret_val make_success(T val=default_success::value)
Definition: ret_val.h:42
static ret_val make_failure(T val=default_failure::value)
Definition: ret_val.h:46
static const std::string flag_RELOAD_EJECT("RELOAD_EJECT")
static const itype_id itype_brass_catcher("brass_catcher")
static const itype_id itype_waterproof_gunmod("waterproof_gunmod")
static const itype_id itype_tuned_mechanism("tuned_mechanism")
static const std::string flag_PUMP_ACTION("PUMP_ACTION")
static const std::string flag_NEVER_JAMS("NEVER_JAMS")
static const std::string flag_WATERPROOF_GUN("WATERPROOF_GUN")
static const std::string flag_PUMP_RAIL_COMPATIBLE("PUMP_RAIL_COMPATIBLE")
gunmod_location location
Where is this gunmod installed (e.g.
Definition: itype.h:548
std::vector< std::unordered_set< weapon_category_id > > usable_category
Definition: itype.h:552
std::unordered_set< itype_id > usable
What kind of weapons can this gunmod be used with (e.g.
Definition: itype.h:551

References _, ammo_remaining(), ammo_types(), count(), debugmsg, flag_NEVER_JAMS(), flag_PUMP_ACTION(), flag_PUMP_RAIL_COMPATIBLE(), flag_RELOAD_EJECT(), flag_WATERPROOF_GUN(), get_free_mod_locations(), get_mod_locations(), gunmod_find(), has_flag(), is_gun(), is_gunmod(), itype_brass_catcher, itype_tuned_mechanism, itype_waterproof_gunmod, islot_gunmod::location, magazine_current(), ret_val< T >::make_failure(), ret_val< T >::make_success(), gunmod_location::name(), gunmod_location::str(), typeId(), islot_gunmod::usable, and islot_gunmod::usable_category.

Referenced by gunmod_inventory_preset::get_denial(), avatar_funcs::gunmod_add(), and activity_handlers::gunmod_add_finish().

◆ is_holster()

bool item::is_holster ( ) const

Definition at line 6602 of file item.cpp.

6603{
6604 return type->can_use( "holster" );
6605}

References itype::can_use(), and type.

Referenced by character_funcs::find_reloadables(), and get_total_capacity().

◆ is_irremovable()

bool item::is_irremovable ( ) const

Definition at line 6800 of file item.cpp.

6801{
6802 return has_flag( flag_IRREMOVABLE );
6803}
static const std::string flag_IRREMOVABLE("IRREMOVABLE")

References flag_IRREMOVABLE(), and has_flag().

Referenced by allow_crafting_component(), detach_gunmods_actor::can_use(), remove_ammo(), and detach_gunmods_actor::use().

◆ is_magazine()

◆ is_map()

bool item::is_map ( ) const

Definition at line 6739 of file item.cpp.

6740{
6741 return get_category().get_id() == itemcat_maps;
6742}
item_category_id get_id() const
static const item_category_id itemcat_maps("maps")

References get_category(), item_category::get_id(), and itemcat_maps.

Referenced by map::add_item(), and display_name().

◆ is_med_container()

bool item::is_med_container ( ) const

Definition at line 6640 of file item.cpp.

6641{
6642 return !contents.empty() && contents.front().is_medication();
6643}

References contents, item_contents::empty(), item_contents::front(), and is_medication().

Referenced by info().

◆ is_medication()

◆ is_melee() [1/2]

bool item::is_melee ( ) const

Is this item an effective melee weapon for any damage type?

See also
item::is_gun()
Note
an item can be both a gun and melee weapon concurrently

Definition at line 6692 of file item.cpp.

6693{
6694 for( int idx = DT_NULL + 1; idx != NUM_DT; ++idx ) {
6695 if( is_melee( static_cast<damage_type>( idx ) ) ) {
6696 return true;
6697 }
6698 }
6699 return false;
6700}

References DT_NULL, is_melee(), and NUM_DT.

Referenced by contextualize_skill(), is_melee(), melee_skill(), and on_wield().

◆ is_melee() [2/2]

bool item::is_melee ( damage_type  dt) const

Is this item an effective melee weapon for the given damage type?

Definition at line 6702 of file item.cpp.

6703{
6704 return damage_melee( dt ) > MELEE_STAT;
6705}
static constexpr int MELEE_STAT

References damage_melee(), and MELEE_STAT.

Referenced by iexamine::cvdmachine(), Character::i_add(), tutorial_game::post_action(), and npc::wield_better_weapon().

◆ is_money()

bool item::is_money ( ) const

Definition at line 6025 of file item.cpp.

6026{
6027 return ammo_types().count( ammotype( "money" ) );
6028}

References ammo_types().

Referenced by ammo_set(), display_name(), inventory_selector_preset::get_caption(), selection_column_preset::get_caption(), operator<(), and stacks_with().

◆ is_non_resealable_container()

bool item::is_non_resealable_container ( ) const

Whether removing this item's contents will permanently alter it.

Definition at line 6754 of file item.cpp.

6755{
6756 return type->container && !type->container->seals && type->container->unseals_into;
6757}

References itype::container, and type.

Referenced by deserialize(), advanced_inventory::move_content(), and on_contents_changed().

◆ is_null()

bool item::is_null ( ) const

Definition at line 735 of file item.cpp.

736{
737 // Actually, type should never by null at all.
738 return ( type == nullptr || type == nullitem() || typeId().is_null() );
739}

References is_null(), nullitem(), type, and typeId().

Referenced by acid_resist(), npc::address_needs(), ammo_set(), base_volume(), bash_resist(), Character::block_hit(), Character::block_ranged_hit(), bullet_resist(), Character::can_eat(), vehicle_part::can_reload(), repair_item_actor::can_repair_target(), Character::can_use(), debug_menu::character_edit_menu(), color(), colorized_feature_description_at(), veh_interact::complete_vehicle(), conductive(), Character::consume_item(), cut_resist(), damage_melee(), display_name(), anonymous_namespace{iexamine.cpp}::atm_menu::do_transfer_all_money(), anonymous_namespace{iexamine.cpp}::atm_menu::do_withdraw_money(), drop_or_embed_projectile(), enumerate_objects_around_point(), Character::extended_description(), final_info(), find_auto_consume(), fire_resist(), inventory::form_from_map(), iexamine::gaspump(), liquid_handler::get_liquid_target(), SkillLevelMap::get_skill_level(), aim_activity_actor::get_weapon(), Character::handle_melee_wear(), npc::has_healing_item(), npc::heal_player(), npc::heal_self(), Character::i_add_or_drop(), info(), npc_trading::init_buying(), Character::is_armed(), is_null(), is_old_owner(), is_owned_by(), is_salvageable(), is_unarmed_weapon(), Character::item_encumb(), Character::item_reload_cost(), npc::load(), made_of(), Character::meets_requirements(), Character::melee_attack(), melee_train(), Item_modifier::modify(), explosion_handler::ExplosionProcess::move_entity(), item_location::impl::item_on_map::obtain(), item_location::impl::item_on_person::obtain(), item_location::impl::item_on_vehicle::obtain(), item_location::impl::item_in_container::obtain(), item_location::impl::item_on_map::obtain_cost(), item_location::impl::item_on_person::obtain_cost(), item_location::impl::item_on_vehicle::obtain_cost(), monexamine::pet_menu(), photo_def_for_camera_point(), rcdrive(), player::reduce_charges(), reinforceable(), bandolier_actor::reload(), reload(), Character::roll_bash_damage(), Character::roll_cut_damage(), Character::roll_stab_damage(), projectile::set_drop(), set_snippet(), npc::shop_restock(), map::spawn_items(), starting_inv(), Character::store(), npc::store(), holster_actor::store(), Character::suffer_from_schizophrenia(), Character::throw_range(), tname(), salvage_actor::try_to_cut_up(), Character::unarmed_attack(), Character::unwield(), avatar_funcs::use_item(), npc::use_painkiller(), salvage_actor::valid_to_cut_up(), volume(), martialart::weapon_valid(), Character::wear_possessed(), weight(), npc::wield(), avatar::wield(), and npc::wield_better_weapon().

◆ is_old_owner()

bool item::is_old_owner ( const Character c,
bool  available_to_take = false 
) const

Definition at line 1252 of file item.cpp.

1253{
1254 if( get_old_owner().is_null() ) {
1255 return available_to_take;
1256 }
1257 if( !c.get_faction() ) {
1258 debugmsg( "Character %s has no faction.", c.disp_name() );
1259 return false;
1260 }
1261 return c.get_faction()->id == get_old_owner();
1262}
faction_id get_old_owner() const
Definition: item.cpp:1288

References c, debugmsg, get_old_owner(), and is_null().

◆ is_owned_by()

bool item::is_owned_by ( const Character c,
bool  available_to_take = false 
) const

Definition at line 1237 of file item.cpp.

1238{
1239 // owner.is_null() implies faction_id( "no_faction" ) which shouldn't happen, or no owner at all.
1240 // either way, certain situations this means the thing is available to take.
1241 // in other scenarios we actually really want to check for id == id, even for no_faction
1242 if( get_owner().is_null() ) {
1243 return available_to_take;
1244 }
1245 if( !c.get_faction() ) {
1246 debugmsg( "Character %s has no faction", c.disp_name() );
1247 return false;
1248 }
1249 return c.get_faction()->id == get_owner();
1250}

References c, debugmsg, get_owner(), and is_null().

Referenced by activity_on_turn_move_loot(), move_items_activity_actor::do_turn(), find_auto_consume(), handle_pickup_ownership(), npc_trading::init_buying(), pick_one_up(), pickup::pick_up(), query_consume_ownership(), and npc::wants_to_sell().

◆ is_pet_armor()

bool item::is_pet_armor ( bool  on_pet = false) const

Definition at line 6723 of file item.cpp.

6724{
6725 bool is_worn = on_pet && !get_var( "pet_armor", "" ).empty();
6726 return has_flag( flag_IS_PET_ARMOR ) && ( is_worn || !on_pet );
6727}
static const std::string flag_IS_PET_ARMOR("IS_PET_ARMOR")

References flag_IS_PET_ARMOR(), get_var(), and has_flag().

Referenced by animal_armor_info(), armor_protection_info(), get_base_env_resist(), get_base_env_resist_w_filter(), get_env_resist(), get_pet_armor_bodytype(), get_pet_armor_max_vol(), get_pet_armor_min_vol(), get_storage(), and get_thickness().

◆ is_power_armor()

bool item::is_power_armor ( ) const

Whether this is a power armor item.

Not necessarily the main armor, it could be a helmet or similar.

Definition at line 5811 of file item.cpp.

5812{
5815}
static const std::string flag_POWERARMOR_MOD("POWERARMOR_MOD")

References flag_POWERARMOR_EXO(), flag_POWERARMOR_EXTERNAL(), flag_POWERARMOR_MOD(), and has_flag().

Referenced by armor_fit_info(), Character::can_wear(), Character::consume_charges(), final_info(), Character::has_enough_charges(), process_tool(), units_remaining(), and set_transform_iuse::use().

◆ is_relic()

bool item::is_relic ( ) const

Definition at line 6998 of file item.cpp.

6999{
7000 return !!relic_data;
7001}

References relic_data.

Referenced by get_enchantments(), mutations_from_wearing(), process_relic(), and stacks_with().

◆ is_reloadable()

bool item::is_reloadable ( ) const

Is it ever possible to reload this item? Only the base item is considered with any mods ignored.

See also
player::can_reload()

Definition at line 9859 of file item.cpp.

9860{
9862 return false; // turrets ignore NO_RELOAD flag
9863
9864 } else if( is_bandolier() ) {
9865 return true;
9866
9867 } else if( is_container() ) {
9868 return true;
9869
9870 } else if( !is_gun() && !is_tool() && !is_magazine() ) {
9871 return false;
9872
9873 } else if( ammo_types().empty() ) {
9874 return false;
9875 }
9876
9877 return true;
9878}
static const std::string flag_VEHICLE("VEHICLE")

References ammo_types(), flag_NO_RELOAD(), flag_VEHICLE(), has_flag(), is_bandolier(), is_container(), is_gun(), is_magazine(), and is_tool().

Referenced by can_reload_item_or_mods(), is_reloadable_helper(), and examine_item_menu::rate_action_reload().

◆ is_reloadable_helper()

bool item::is_reloadable_helper ( const itype_id ammo,
bool  now 
) const
private

Helper for checking reloadability.

Definition at line 6901 of file item.cpp.

6902{
6903 // empty ammo is passed for listing possible ammo apparently, so it needs to return true.
6904 if( !is_reloadable() ) {
6905 return false;
6906 } else if( is_watertight_container() ) {
6907 if( ammo.is_empty() ) {
6908 return now ? !is_container_full() : true;
6909 } else if( ammo->phase != LIQUID ) {
6910 return false;
6911 } else {
6912 return now ? ( is_container_empty() || contents.front().typeId() == ammo ) : true;
6913 }
6914 } else if( magazine_integral() ) {
6915 if( !ammo.is_empty() ) {
6916 if( now && ammo_data() ) {
6917 if( ammo_current() != ammo ) {
6918 return false;
6919 }
6920 } else {
6921 const itype *at = &*ammo;
6922 if( ( !at->ammo || !ammo_types().count( at->ammo->type ) ) &&
6923 !magazine_compatible().count( ammo ) ) {
6924 return false;
6925 }
6926 }
6927 }
6928 return now ? ( ammo_remaining() < ammo_capacity() ) : true;
6929 } else {
6930 return ammo.is_empty() ? true : magazine_compatible().count( ammo );
6931 }
6932}
bool is_reloadable() const
Is it ever possible to reload this item? Only the base item is considered with any mods ignored.
Definition: item.cpp:9859
bool is_container_full(bool allow_bucket=false) const
Whether this item has no more free capacity for its current content.
Definition: item.cpp:6867

References itype::ammo, ammo_capacity(), ammo_current(), ammo_data(), ammo_remaining(), ammo_types(), contents, count(), item_contents::front(), is_container_empty(), is_container_full(), string_id< T >::is_empty(), is_reloadable(), is_watertight_container(), LIQUID, magazine_compatible(), magazine_integral(), itype::phase, and typeId().

Referenced by can_reload_with(), and is_reloadable_with().

◆ is_reloadable_with()

bool item::is_reloadable_with ( const itype_id ammo) const

Returns true if this item can be reloaded with specified ammo type at this moment.

Definition at line 6896 of file item.cpp.

6897{
6898 return is_reloadable_helper( ammo, true );
6899}

References is_reloadable_helper().

Referenced by Character::can_reload(), vehicle_part::can_reload(), fill_with(), get_remaining_capacity_for_liquid(), and reload().

◆ is_salvageable()

bool item::is_salvageable ( ) const

Definition at line 6934 of file item.cpp.

6935{
6936 if( is_null() ) {
6937 return false;
6938 }
6939 const std::vector<material_id> &mats = made_of();
6940 if( std::none_of( mats.begin(), mats.end(), []( const material_id & m ) {
6941 return m->salvaged_into().has_value();
6942 } ) ) {
6943 return false;
6944 }
6945 return !has_flag( flag_NO_SALVAGE );
6946}
static const std::string flag_NO_SALVAGE("NO_SALVAGE")

References flag_NO_SALVAGE(), has_flag(), is_null(), and made_of().

Referenced by salvage_actor::try_to_cut_up(), and salvage_actor::valid_to_cut_up().

◆ is_seed()

bool item::is_seed ( ) const

Whether this is actually a seed, the seed functions won't be of much use for non-seeds.

Definition at line 9803 of file item.cpp.

9804{
9805 return !!type->seed;
9806}

References itype::seed, and type.

Referenced by can_do_activity_there(), iexamine::dirtmound(), farm_valid_seed(), talk_function::field_plant(), plot_options::get_zone_name_suggestion(), plot_options::query_seed(), vehicle::reload_seeds(), and map::rotten_item_spawn().

◆ is_sided()

bool item::is_sided ( ) const

Returns true if item is armor and can be worn on different sides of the body.

Definition at line 805 of file item.cpp.

806{
807 const islot_armor *t = find_armor_data();
808 return t ? t->sided : false;
809}

References find_armor_data(), and islot_armor::sided.

Referenced by armor_fit_info(), armor_info(), Character::can_wear(), on_takeoff(), on_wear(), examine_item_menu::rate_action_change_side(), and set_side().

◆ is_silent()

bool item::is_silent ( ) const

Whether this is a (nearly) silent gun (a tiny bit of sound is allowed).

Non-guns are always silent.

Definition at line 6567 of file item.cpp.

6568{
6569 return gun_noise().volume < 5;
6570}
sound_data gun_noise(bool burst=false) const
Returns the sound of the gun being fired.
Definition: ranged.cpp:1815
int volume
Volume of the sound.
Definition: item.h:1850

References gun_noise(), and item::sound_data::volume.

Referenced by npc::check_or_use_weapon_cbm(), and npc::method_of_attack().

◆ is_soft()

bool item::is_soft ( ) const

Is this item flexible enough to be worn on body parts like antlers?

Definition at line 9851 of file item.cpp.

9852{
9853 const std::vector<material_id> mats = made_of();
9854 return std::any_of( mats.begin(), mats.end(), []( const material_id & mid ) {
9855 return mid.obj().soft();
9856 } );
9857}

References made_of().

Referenced by mutation_branch::conflicts_with_item(), and game_menus::inv::multiwash().

◆ is_tainted()

bool item::is_tainted ( ) const

Is item derived from a zombie?

Definition at line 9846 of file item.cpp.

9847{
9848 return corpse && corpse->has_flag( MF_POISON );
9849}
@ MF_POISON
Definition: mtype.h:80

References corpse, mtype::has_flag(), and MF_POISON.

Referenced by food_info().

◆ is_tool()

◆ is_toolmod()

bool item::is_toolmod ( ) const

Definition at line 6790 of file item.cpp.

6791{
6792 return !is_gunmod() && type->mod;
6793}

References is_gunmod(), itype::mod, and type.

Referenced by allow_crafting_component(), item_action_generator::map_actions_to_items(), iuse::multicooker(), and iuse::toolmod_attach().

◆ is_transformable()

bool item::is_transformable ( ) const

Definition at line 6988 of file item.cpp.

6989{
6990 return type->use_methods.find( "transform" ) != type->use_methods.end();
6991}

References type, and itype::use_methods.

Referenced by map::add_item().

◆ is_two_handed()

bool item::is_two_handed ( const Character guy) const

Whether the character needs both hands to wield this item.

Strength determines which weapons can be wielded with one hand

Definition at line 6429 of file item.cpp.

6430{
6431 if( has_flag( flag_ALWAYS_TWOHAND ) ) {
6432 return true;
6433 }
6434 ///\EFFECT_STR determines which weapons can be wielded with one hand
6435 return ( ( weight() / 113_gram ) > guy.str_cur * 4 );
6436}
int str_cur
Definition: character.h:264
static const std::string flag_ALWAYS_TWOHAND("ALWAYS_TWOHAND")

References flag_ALWAYS_TWOHAND(), has_flag(), Character::str_cur, and weight().

Referenced by Character::can_wear(), Character::can_wield(), ranged::gunmode_checks_common(), hardcoded_mutation_attack(), Character::item_handling_cost(), and Character::melee_special_effects().

◆ is_unarmed_weapon()

bool item::is_unarmed_weapon ( ) const

Definition at line 741 of file item.cpp.

742{
743 return has_flag( flag_UNARMED_WEAPON ) || is_null();
744}
static const std::string flag_UNARMED_WEAPON("UNARMED_WEAPON")

References flag_UNARMED_WEAPON(), has_flag(), and is_null().

Referenced by Character::crit_chance(), melee_train(), Character::roll_bash_damage(), Character::roll_cut_damage(), and Character::roll_stab_damage().

◆ is_upgrade()

bool item::is_upgrade ( ) const

Whether the CBM is an upgrade to another bionic module.

Definition at line 10065 of file item.cpp.

10066{
10067 if( !type->bionic ) {
10068 return false;
10069 }
10070 return type->bionic->is_upgrade;
10071}

References itype::bionic, and type.

Referenced by bionic_install_preset::get_denial(), and bionic_install_surgeon_preset::get_denial().

◆ is_watertight_container()

bool item::is_watertight_container ( ) const

◆ is_wheel()

bool item::is_wheel ( ) const

Definition at line 6780 of file item.cpp.

6781{
6782 return !!type->wheel;
6783}
cata::value_ptr< islot_wheel > wheel
Definition: itype.h:825

References type, and itype::wheel.

Referenced by can_do_activity_there(), tname(), wheel_area(), vehicle_part::wheel_diameter(), and vehicle_part::wheel_width().

◆ is_worn_only_with()

bool item::is_worn_only_with ( const item it) const

Returns true whether this item can be worn only when.

Parameters
itis worn.

Definition at line 838 of file item.cpp.

839{
842}

References flag_POWERARMOR_EXO(), flag_POWERARMOR_EXTERNAL(), flag_POWERARMOR_MOD(), and has_flag().

Referenced by Character::get_dependent_worn_items(), and pickup::reorder_for_dropping().

◆ item_has_uses_recursive()

bool item::item_has_uses_recursive ( ) const

Definition at line 80 of file item_action.cpp.

81{
82 if( !type->use_methods.empty() ) {
83 return true;
84 }
85
87}
bool item_has_uses_recursive() const
Definition: item_action.cpp:89

References contents, item_contents::item_has_uses_recursive(), type, and itype::use_methods.

◆ label()

std::string item::label ( unsigned int  quantity = 0) const

Returns label from "item_label" itemvar and quantity.

Definition at line 9981 of file item.cpp.

9982{
9983 if( has_label() ) {
9984 return get_var( "item_label" );
9985 }
9986
9987 return type_name( quantity );
9988}
std::string type_name(unsigned int quantity=1) const
Name of the item type (not the item), with proper plural.
Definition: item.cpp:9880
bool has_label() const
Returns true if item has "item_label" itemvar.
Definition: item.cpp:9976

References get_var(), has_label(), and type_name().

Referenced by tname().

◆ legacy_fast_forward_time()

void item::legacy_fast_forward_time ( )

Definition at line 10044 of file item.cpp.

10045{
10046 const time_duration tmp_bday = ( bday - calendar::turn_zero ) * 6;
10047 bday = calendar::turn_zero + tmp_bday;
10048
10049 rot *= 6;
10050
10051 const time_duration tmp_rot = ( last_rot_check - calendar::turn_zero ) * 6;
10053}

References bday, last_rot_check, and calendar::turn_zero.

Referenced by deserialize(), and submap::load().

◆ lift_strength()

int item::lift_strength ( ) const

Required strength to be able to successfully lift the item unaided by equipment.

Definition at line 5200 of file item.cpp.

5201{
5202 const int mass = units::to_gram( weight() );
5203 return std::max( mass / 10000, 1 );
5204}
constexpr value_type to_gram(const quantity< value_type, mass_in_milligram_tag > &v)
Definition: units_mass.h:68
quantity< std::int64_t, mass_in_milligram_tag > mass
Definition: units_mass.h:23

References units::to_gram(), and weight().

Referenced by can_do_activity_there(), veh_interact::can_remove_part(), and veh_interact::update_part_requirements().

◆ made_of() [1/3]

const std::vector< material_id > & item::made_of ( ) const

The ids of all the materials this is made of.

This may return an empty vector. The returned vector does not contain the null id.

Definition at line 6438 of file item.cpp.

6439{
6440 if( is_corpse() ) {
6441 return corpse->mat;
6442 }
6443 return type->materials;
6444}
std::vector< material_id > materials
Definition: itype.h:890
std::vector< material_id > mat
Definition: mtype.h:254

References corpse, is_corpse(), mtype::mat, itype::materials, and type.

Referenced by activity_on_turn_move_loot(), map::add_item(), map::add_item_or_charges(), avatar_funcs::add_or_drop_with_msg(), iuse::blech(), iuse::blech_because_unclean(), vehicle_part::can_reload(), can_unload_liquid(), saw_stock_actor::can_use_on(), Character::can_wear(), Character::can_wield(), MonsterGenerator::check_monster_definitions(), color_in_inventory(), crafting::complete_disassemble(), compute_default_effective_vitamins(), contents_made_of(), map::create_burnproducts(), auto_pickup::rule_list::create_rule(), salvage_actor::cut_up(), iexamine::cvdmachine(), move_items_activity_actor::do_turn(), Character::drop_invalid_inventory(), drop_or_handle(), final_info(), character_funcs::find_ammo_helper(), iexamine::fvat_empty(), iexamine::fvat_full(), Character::get_acquirable_energy(), get_base_material(), pickup_inventory_preset::get_denial(), comestible_inventory_preset::get_denial(), liquid_handler::get_liquid_target(), get_random_material(), repair_item_actor::handle_components(), liquid_handler::handle_liquid(), Character::i_add_or_drop(), in_container(), is_salvageable(), is_soft(), inscribe_actor::item_inscription(), iexamine::keg(), made_of(), made_of_any(), made_of_types(), Character::melee_special_effects(), Item_modifier::modify(), advanced_inventory::move_all_items(), advanced_inventory::move_content(), move_item(), iuse::multicooker(), npc_pickup_from_stack(), on_drop(), only_made_of(), liquid_handler::perform_liquid_transfer(), pick_one_up(), price(), monster::process_turn(), mattack::pull_metal_weapon(), item_reload_option::qty(), advanced_inventory::query_charges(), reload(), simulate_burn(), smash(), map::spawn_an_item(), starting_inv(), ranged::throw_item(), tname(), try_fuel_fire(), avatar_funcs::unload_item(), npc::value(), volume(), and Character::warmth().

◆ made_of() [2/3]

bool item::made_of ( const material_id mat_ident) const

Check we are made of this material (e.g.

matches at least one in our set.)

Definition at line 6484 of file item.cpp.

6485{
6486 const std::vector<material_id> &materials = made_of();
6487 return std::find( materials.begin(), materials.end(), mat_ident ) != materials.end();
6488}

References detail::find(), and made_of().

◆ made_of() [3/3]

bool item::made_of ( phase_id  phase) const

Are we solid, liquid, gas, plasma?

Definition at line 6495 of file item.cpp.

6496{
6497 if( is_null() ) {
6498 return false;
6499 }
6500 return type->phase == phase;
6501}

References is_null(), itype::phase, and type.

◆ made_of_any()

bool item::made_of_any ( const std::set< material_id > &  mat_idents) const

Check we are made of at least one of a set (e.g.

true if at least one item of the passed in set matches any material).

Parameters
mat_identsSet of material ids.

Definition at line 6460 of file item.cpp.

6461{
6462 const std::vector<material_id> &mats = made_of();
6463 if( mats.empty() ) {
6464 return false;
6465 }
6466
6467 return std::any_of( mats.begin(), mats.end(), [&mat_idents]( const material_id & e ) {
6468 return mat_idents.count( e );
6469 } );
6470}

References made_of().

Referenced by Character::can_eat(), goes_bad(), repair_inventory_preset::is_shown(), inscribe_actor::item_inscription(), ranged::throw_item(), and Character::throw_range().

◆ made_of_types()

std::vector< const material_type * > item::made_of_types ( ) const

Same as made_of(), but returns the material_type directly.

Definition at line 6451 of file item.cpp.

6452{
6453 std::vector<const material_type *> material_types_composed_of;
6454 for( const material_id &mat_id : made_of() ) {
6455 material_types_composed_of.push_back( &mat_id.obj() );
6456 }
6457 return material_types_composed_of;
6458}

References made_of().

Referenced by acid_resist(), bash_resist(), basic_info(), bullet_resist(), chip_resistance(), conductive(), cut_resist(), fire_resist(), flammable(), reinforceable(), and wind_resist().

◆ magazine_compatible()

std::set< itype_id > item::magazine_compatible ( bool  conversion = true) const

Get compatible magazines (if any) for this item.

Parameters
conversionwhether to include the effect of any flags or mods which convert item's ammo type
Returns
magazine compatibility which is always empty if item has integral magazine
See also
item::magazine_integral

Definition at line 7713 of file item.cpp.

7714{
7715 std::set<itype_id> mags = {};
7716 // mods that define magazine_adaptor may override the items usual magazines
7717 const std::vector<const item *> &mods = is_gun() ? gunmods() : toolmods();
7718 for( const item *m : mods ) {
7719 if( !m->type->mod->magazine_adaptor.empty() ) {
7720 for( const ammotype &atype : ammo_types( conversion ) ) {
7721 if( m->type->mod->magazine_adaptor.count( atype ) ) {
7722 std::set<itype_id> magazines_for_atype = m->type->mod->magazine_adaptor.find( atype )->second;
7723 mags.insert( magazines_for_atype.begin(), magazines_for_atype.end() );
7724 }
7725 }
7726 return mags;
7727 }
7728 }
7729
7730 for( const ammotype &atype : ammo_types( conversion ) ) {
7731 if( type->magazines.count( atype ) ) {
7732 std::set<itype_id> magazines_for_atype = type->magazines.find( atype )->second;
7733 mags.insert( magazines_for_atype.begin(), magazines_for_atype.end() );
7734 }
7735 }
7736 return mags;
7737}

References ammo_types(), gunmods(), is_gun(), itype::magazines, toolmods(), and type.

Referenced by mdeath::broken(), color_in_inventory(), character_funcs::find_reloadables(), gun_info(), avatar_funcs::gunmod_add(), is_reloadable_helper(), and tool_info().

◆ magazine_current() [1/2]

item * item::magazine_current ( )

Currently loaded magazine (if any)

Returns
current magazine or nullptr if either no magazine loaded or item has integral magazine
See also
item::magazine_integral

Definition at line 7739 of file item.cpp.

7740{
7741 return contents.get_item_with(
7742 []( const item & it ) {
7743 return it.is_magazine();
7744 } );
7745}
item * get_item_with(const std::function< bool(const item &)> &filter)

References contents, item_contents::get_item_with(), and is_magazine().

Referenced by ammo_capacity(), ammo_consume(), ammo_data(), ammo_remaining(), ammo_set(), ammo_unset(), item_funcs::can_be_unloaded(), turret_data::can_unload(), common_ammo_default(), cycle_action(), iuse::foodperson(), iuse::hand_crank(), is_gunmod_compatible(), character_funcs::list_ammo(), magazine_current(), Item_modifier::modify(), reload(), character_funcs::select_ammo(), tool_info(), iuse::toolmod_attach(), avatar_funcs::unload_item(), volume(), and weight().

◆ magazine_current() [2/2]

const item * item::magazine_current ( ) const

Definition at line 7747 of file item.cpp.

7748{
7749 return const_cast<item *>( this )->magazine_current();
7750}

References magazine_current().

◆ magazine_default()

itype_id item::magazine_default ( bool  conversion = true) const

Get the default magazine type (if any) for the current effective ammo type.

Parameters
conversionwhether to include the effect of any flags or mods which convert item's ammo type
Returns
magazine type or "null" if item has integral magazine or no magazines for current ammo type

Definition at line 7692 of file item.cpp.

7693{
7694 if( !ammo_types( conversion ).empty() ) {
7695 if( conversion ) {
7696 for( const item *m : is_gun() ? gunmods() : toolmods() ) {
7697 if( !m->type->mod->magazine_adaptor.empty() ) {
7698 auto mags = m->type->mod->magazine_adaptor.find( ammotype( *ammo_types( conversion ).begin() ) );
7699 if( mags != m->type->mod->magazine_adaptor.end() ) {
7700 return *( mags->second.begin() );
7701 }
7702 }
7703 }
7704 }
7705 auto mag = type->magazine_default.find( ammotype( *ammo_types( conversion ).begin() ) );
7706 if( mag != type->magazine_default.end() ) {
7707 return mag->second;
7708 }
7709 }
7710 return itype_id::NULL_ID();
7711}
std::map< ammotype, itype_id > magazine_default
Default magazine for each ammo type that can be used to reload this item.
Definition: itype.h:991

References ammo_types(), gunmods(), is_gun(), itype::magazine_default, itype::mod, string_id< itype >::NULL_ID(), toolmods(), and type.

Referenced by ammo_capacity(), ammo_set(), defense_game::caravan(), game::dump_stats(), and Item_modifier::modify().

◆ magazine_info()

void item::magazine_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 1884 of file item.cpp.

1886{
1887 if( !is_magazine() || has_flag( flag_NO_RELOAD ) ) {
1888 return;
1889 }
1890
1891 if( parts->test( iteminfo_parts::MAGAZINE_CAPACITY ) ) {
1892 for( const ammotype &at : ammo_types() ) {
1893 const std::string fmt = string_format( vgettext( "<num> round of %s",
1894 "<num> rounds of %s", ammo_capacity() ),
1895 at->name() );
1896 info.emplace_back( "MAGAZINE", _( "Capacity: " ), fmt, iteminfo::no_flags,
1897 ammo_capacity() );
1898 }
1899 }
1900 if( parts->test( iteminfo_parts::MAGAZINE_RELOAD ) ) {
1901 info.emplace_back( "MAGAZINE", _( "Reload time: " ), _( "<num> moves per round" ),
1902 iteminfo::lower_is_better, type->magazine->reload_time );
1903 }
1905}

References _, ammo_capacity(), ammo_types(), flag_NO_RELOAD(), has_flag(), info(), insert_separation_line(), is_magazine(), iteminfo::lower_is_better, itype::magazine, MAGAZINE_CAPACITY, MAGAZINE_RELOAD, iteminfo::no_flags, string_format(), iteminfo_query::test(), type, and vgettext().

Referenced by info().

◆ magazine_integral()

bool item::magazine_integral ( ) const

Does item have an integral magazine (as opposed to allowing detachable magazines)

Definition at line 7677 of file item.cpp.

7678{
7679 if( is_gun() && type->gun->clip > 0 ) {
7680 return true;
7681 }
7682 for( const item *m : is_gun() ? gunmods() : toolmods() ) {
7683 if( !m->type->mod->magazine_adaptor.empty() ) {
7684 return false;
7685 }
7686 }
7687
7688 // We have an integral magazine if we're a gun with an ammo capacity (clip) or we have no magazines.
7689 return ( is_gun() && type->gun->clip > 0 ) || type->magazines.empty();
7690}

References itype::gun, gunmods(), is_gun(), itype::magazines, toolmods(), and type.

Referenced by character_funcs::ammo_count_for(), ammo_set(), ammo_unset(), turret_data::can_reload(), defense_game::caravan(), color_in_inventory(), game::dump_stats(), character_funcs::fmt_wielded_weapon(), gun_info(), avatar_funcs::gunmod_add(), ideal_ranged_dps(), is_reloadable_helper(), item(), Item_modifier::modify(), price(), reload(), character_funcs::select_ammo(), tool_info(), wants_to_reload_with(), and weight().

◆ make_component_hash()

uint64_t item::make_component_hash ( ) const

Creates a hash from the itype_ids of this item's components.

Definition at line 8934 of file item.cpp.

8935{
8936 // First we need to sort the IDs so that identical ingredients give identical hashes.
8937 std::multiset<std::string> id_set;
8938 for( const item &it : components ) {
8939 id_set.insert( it.typeId().str() );
8940 }
8941
8942 std::string concatenated_ids;
8943 for( std::string id : id_set ) {
8944 concatenated_ids += id;
8945 }
8946
8947 std::hash<std::string> hasher;
8948 return hasher( concatenated_ids );
8949}

References components, base_camps::id, and string_id< T >::str().

Referenced by consumption_event::consumption_event(), and Character::fun_for().

◆ make_corpse()

item item::make_corpse ( const mtype_id mt = string_id<mtype>::NULL_ID(),
time_point  turn = calendar::turn,
const std::string &  name = "",
int  upgrade_time = -1 
)
static

Make a corpse of the given monster type.

The monster type id must be valid (see MonsterGenerator::get_all_mtypes).

The turn parameter sets the birthday of the corpse, in other words: the turn when the monster died. Because corpses are removed from the map when they reach a certain age, one has to be careful when placing corpses with a birthday of 0. They might be removed immediately when the map is loaded without been seen by the player.

The name parameter can be used to give the corpse item a name. This is used instead of the monster type name ("corpse of X" instead of "corpse of bear").

With the default parameters it makes a human corpse, created at the current turn.

Definition at line 510 of file item.cpp.

512{
513 if( !mt.is_valid() ) {
514 debugmsg( "tried to make a corpse with an invalid mtype id" );
515 }
516
517 std::string corpse_type = mt == mtype_id::NULL_ID() ? "corpse_generic_human" : "corpse";
518
519 item result( corpse_type, turn );
520 result.corpse = &mt.obj();
521
522 if( result.corpse->has_flag( MF_REVIVES ) ) {
523 if( one_in( 20 ) ) {
524 result.set_flag( "REVIVE_SPECIAL" );
525 }
526 result.set_var( "upgrade_time", std::to_string( upgrade_time ) );
527 }
528
529 // This is unconditional because the const itemructor above sets result.name to
530 // "human corpse".
531 result.corpse_name = name;
532
533 return result;
534}
std::string to_string(const time_duration &d)
Returns a string showing a duration.
Definition: calendar.cpp:327
bool one_in(int chance)
Definition: rng.cpp:65

References debugmsg, string_id< T >::is_valid(), MF_REVIVES, om_direction::name(), string_id< mtype >::NULL_ID(), string_id< T >::obj(), one_in(), to_string(), and calendar::turn.

Referenced by map::add_corpse(), game::catch_a_monster(), Single_item_creator::create_single(), map::draw_mine(), iuse::fish_trap(), basecamp::hunting_results(), make_mon_corpse(), MapExtras::mx_grave(), MapExtras::mx_mayhem(), MapExtras::mx_minefield(), Character::place_corpse(), rod_fish(), and mdeath::splatter().

◆ mark_as_used_by_player()

void item::mark_as_used_by_player ( const player p)

Marks the item as being used by this specific player, it remains unmarked for other players.

The player is identified by its id.

Definition at line 8882 of file item.cpp.

8883{
8884 std::string &used_by_ids = item_vars[ USED_BY_IDS ];
8885 if( used_by_ids.empty() ) {
8886 // *always* start with a ';'
8887 used_by_ids = ";";
8888 }
8889 // and always end with a ';'
8890 used_by_ids += string_format( "%d;", p.getID().get_value() );
8891}

References character_id::get_value(), Character::getID(), item_vars, string_format(), and USED_BY_IDS().

Referenced by reveal_map_actor::use().

◆ mark_chapter_as_read()

void item::mark_chapter_as_read ( const Character ch)

Mark one chapter of the book as read by the given player.

May do nothing if the book has no unread chapters. This is a per-character setting, see get_remaining_chapters.

Definition at line 7128 of file item.cpp.

7129{
7130 const std::string var = string_format( "remaining-chapters-%d", ch.getID().get_value() );
7131 if( type->book && type->book->chapters == 0 ) {
7132 // books without chapters will always have remaining chapters == 0, so we don't need to store them
7133 erase_var( var );
7134 return;
7135 }
7136 const int remain = std::max( 0, get_remaining_chapters( ch ) - 1 );
7137 set_var( var, remain );
7138}
void erase_var(const std::string &name)
Erase the value of the given variable.
Definition: item.cpp:1083

References itype::book, erase_var(), get_remaining_chapters(), character_id::get_value(), Character::getID(), set_var(), string_format(), and type.

Referenced by avatar::do_read(), and npc::finish_read().

◆ max_damage()

◆ med_info()

void item::med_info ( const item med_item,
std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 1644 of file item.cpp.

1646{
1647 const cata::value_ptr<islot_comestible> &med_com = med_item->get_comestible();
1648 if( med_com->quench != 0 && parts->test( iteminfo_parts::MED_QUENCH ) ) {
1649 info.push_back( iteminfo( "MED", _( "Quench: " ), med_com->quench ) );
1650 }
1651
1652 if( med_item->get_comestible_fun() != 0 && parts->test( iteminfo_parts::MED_JOY ) ) {
1653 info.push_back( iteminfo( "MED", _( "Enjoyability: " ),
1654 get_avatar().fun_for( *med_item ).first ) );
1655 }
1656
1657 if( med_com->stim != 0 && parts->test( iteminfo_parts::MED_STIMULATION ) ) {
1658 std::string name = string_format( "%s <stat>%s</stat>", _( "Stimulation:" ),
1659 med_com->stim > 0 ? _( "Upper" ) : _( "Downer" ) );
1660 info.push_back( iteminfo( "MED", name ) );
1661 }
1662
1663 if( parts->test( iteminfo_parts::MED_PORTIONS ) ) {
1664 info.push_back( iteminfo( "MED", _( "Portions: " ),
1665 std::abs( static_cast<int>( med_item->charges ) * batch ) ) );
1666 }
1667
1668 if( med_com->addict && parts->test( iteminfo_parts::DESCRIPTION_MED_ADDICTING ) ) {
1669 info.emplace_back( "DESCRIPTION", _( "* Consuming this item is <bad>addicting</bad>." ) );
1670 }
1671}
int get_comestible_fun() const
Definition: item.cpp:5507

References _, charges, DESCRIPTION_MED_ADDICTING, get_avatar(), get_comestible(), get_comestible_fun(), info(), MED_JOY, MED_PORTIONS, MED_QUENCH, MED_STIMULATION, om_direction::name(), string_format(), and iteminfo_query::test().

Referenced by info().

◆ melee_skill()

skill_id item::melee_skill ( ) const

The most relevant skill used with this melee weapon.

Can be "null" if this is not a weapon. Note this function returns null if the item is a gun for which you can use gun_skill() instead.

Definition at line 7220 of file item.cpp.

7221{
7222 if( !is_melee() ) {
7223 return skill_id::NULL_ID();
7224 }
7225
7226 if( has_flag( flag_UNARMED_WEAPON ) ) {
7227 return skill_unarmed;
7228 }
7229
7230 int hi = 0;
7232
7233 for( int idx = DT_NULL + 1; idx != NUM_DT; ++idx ) {
7234 const int val = damage_melee( static_cast<damage_type>( idx ) );
7235 const skill_id &sk = skill_by_dt( static_cast<damage_type>( idx ) );
7236 if( val > hi && sk ) {
7237 hi = val;
7238 res = sk;
7239 }
7240 }
7241
7242 return res;
7243}
const skill_id & skill_by_dt(damage_type dt)
Definition: damage.cpp:273
static const skill_id skill_unarmed("unarmed")

References damage_melee(), DT_NULL, flag_UNARMED_WEAPON(), has_flag(), is_melee(), string_id< Skill >::NULL_ID(), NUM_DT, skill_by_dt(), and skill_unarmed.

Referenced by contextualize_skill(), Character::crit_chance(), Character::get_hit_weapon(), Character::item_store_cost(), on_wield(), and character_funcs::try_wield_contents().

◆ merge_charges()

bool item::merge_charges ( const item rhs)

Merge charges of the other item into this item.

Returns
true if the items have been merged, otherwise false. Merging is only done for items counted by charges (count_by_charges) and items that stack together (stacks_with).

Definition at line 979 of file item.cpp.

980{
981 if( !count_by_charges() || !stacks_with( rhs ) ) {
982 return false;
983 }
984 // Prevent overflow when either item has "near infinite" charges.
985 if( charges >= INFINITE_CHARGES / 2 || rhs.charges >= INFINITE_CHARGES / 2 ) {
987 return true;
988 }
989 // We'll just hope that the item counter represents the same thing for both items
990 if( item_counter > 0 || rhs.item_counter > 0 ) {
991 item_counter = ( static_cast<double>( item_counter ) * charges + static_cast<double>
992 ( rhs.item_counter ) * rhs.charges ) / ( charges + rhs.charges );
993 }
994 charges += rhs.charges;
995 return true;
996}

References charges, count_by_charges(), INFINITE_CHARGES, item_counter, and stacks_with().

Referenced by vehicle::add_item().

◆ min_damage()

int item::min_damage ( ) const

Minimum amount of damage to an item (state of maximum repair)

Definition at line 6236 of file item.cpp.

6237{
6238 return type->damage_min();
6239}
int damage_min() const
Definition: itype.cpp:46

References itype::damage_min(), and type.

Referenced by repair_item_actor::can_repair_target(), damage_color(), repair_item_actor::default_action(), iuse::gun_repair(), io(), mod_damage(), and set_damage().

◆ minimum_freshness_duration()

time_duration item::minimum_freshness_duration ( temperature_flag  temperature) const

Time that this item is guaranteed to stay fresh.

Parameters
temperatureTemperature flag used to cap the duration.
Returns
Remaining guaranteed freshness duration, assuming current storage conditions.

Definition at line 5725 of file item.cpp.

5726{
5728 unsigned long long rot_per_hour = get_hourly_rotpoints_at_temp( temperature_f );
5729
5730 if( rot_per_hour <= 0 || !type->comestible ) {
5732 }
5733
5734 time_duration remaining_rot = type->comestible->spoils - rot;
5735 // Has to be in int64 or it will overflow for long lasting food
5736 unsigned long long duration = to_turns<unsigned long long>( remaining_rot )
5737 * to_turns<unsigned long long>( 1_hours )
5738 / rot_per_hour;
5739 if( duration > to_turns<unsigned long long>( calendar::INDEFINITELY_LONG_DURATION ) ) {
5741 }
5742
5743 return time_duration::from_turns( static_cast<int>( duration ) );
5744}
static int temperature_flag_to_highest_temperature(temperature_flag temperature)
Definition: item.cpp:5707
const time_duration INDEFINITELY_LONG_DURATION
The expected duration of the cataclysm.

References itype::comestible, time_duration::from_turns(), get_hourly_rotpoints_at_temp(), calendar::INDEFINITELY_LONG_DURATION, rot, temperature_flag_to_highest_temperature(), and type.

Referenced by food_info().

◆ mitigate_damage()

void item::mitigate_damage ( damage_unit du) const

Assuming that specified du hit the armor, reduce du based on the item's resistance to the damage type.

This will never reduce du.amount below 0.

Definition at line 6388 of file item.cpp.

6389{
6390 const resistances res = resistances( *this );
6391 const float mitigation = res.get_effective_resist( du );
6392 du.amount -= mitigation;
6393 du.amount = std::max( 0.0f, du.amount );
6394}
float get_effective_resist(const damage_unit &du) const
Definition: damage.cpp:217

References damage_unit::amount, and resistances::get_effective_resist().

Referenced by Character::armor_absorb(), and character_funcs::is_bp_immune_to().

◆ mod_charges()

void item::mod_charges ( int  mod)

Modify the charges of this item, only use for items counted by charges! The item must have enough charges for this (>= quantity) and be counted by charges.

Parameters
modHow many charges should be removed.

Definition at line 9750 of file item.cpp.

9751{
9752 if( has_infinite_charges() ) {
9753 return;
9754 }
9755
9756 if( !count_by_charges() ) {
9757 debugmsg( "Tried to remove %s by charges, but item is not counted by charges.", tname() );
9758 } else if( mod < 0 && charges + mod < 0 ) {
9759 debugmsg( "Tried to remove charges that do not exist, removing maximum available charges instead." );
9760 charges = 0;
9761 } else if( mod > 0 && charges >= INFINITE_CHARGES - mod ) {
9762 charges = INFINITE_CHARGES - 1; // Highly unlikely, but finite charges should not become infinite.
9763 } else {
9764 charges += mod;
9765 }
9766}

References charges, count_by_charges(), debugmsg, has_infinite_charges(), INFINITE_CHARGES, and tname().

Referenced by throw_activity_actor::do_turn(), Character::eat(), fill_with(), player::reduce_charges(), and talk_effect_fun_t::set_u_buy_item().

◆ mod_damage() [1/2]

bool item::mod_damage ( int  qty)

same as other mod_damage, but uses DT_NULL as damage type.

Definition at line 6273 of file item.cpp.

6274{
6275 return mod_damage( qty, DT_NULL );
6276}

References DT_NULL, and mod_damage().

◆ mod_damage() [2/2]

bool item::mod_damage ( int  qty,
damage_type  dt 
)

Apply damage to const itemrained by min_damage and max_damage.

Parameters
qtymaximum amount by which to adjust damage (negative permissible)
dttype of damage which may be passed to on_damage callback
Returns
whether item should be destroyed

Definition at line 6251 of file item.cpp.

6252{
6253 bool destroy = false;
6254
6255 if( count_by_charges() ) {
6256 charges -= std::min( type->stack_size * qty / itype::damage_scale, charges );
6257 destroy |= charges == 0;
6258 }
6259
6260 if( qty > 0 ) {
6261 on_damage( qty, dt );
6262 }
6263
6264 if( !count_by_charges() ) {
6265 destroy |= damage_ + qty > max_damage();
6266
6267 damage_ = std::max( std::min( damage_ + qty, max_damage() ), min_damage() );
6268 }
6269
6270 return destroy;
6271}
void on_damage(int qty, damage_type dt)
Callback immediately before an item is damaged.
Definition: item.cpp:4567

References charges, count_by_charges(), damage_, itype::damage_scale, max_damage(), min_damage(), on_damage(), itype::stack_size, and type.

Referenced by Character::armor_absorb(), iuse::gun_repair(), inc_damage(), activity_handlers::make_zlave_finish(), mod_damage(), vehicle::mod_hp(), and repair_item_actor::repair().

◆ mod_energy()

units::energy item::mod_energy ( const units::energy qty)

Add or remove energy from a battery.

If adding the specified energy quantity would go over the battery's capacity fill the battery and ignore the remainder. If adding the specified energy quantity would reduce the battery's charge level below 0 do nothing and return how far below 0 it would have gone.

Parameters
qtyenergy quantity to add (can be negative)
Returns
0 valued energy quantity on success

Definition at line 575 of file item.cpp.

576{
577 if( !is_battery() ) {
578 debugmsg( "Tried to set energy of non-battery item" );
579 return 0_J;
580 }
581
582 units::energy val = energy_remaining() + qty;
583 if( val < 0_J ) {
584 return val;
585 } else if( val > type->battery->max_capacity ) {
586 energy = type->battery->max_capacity;
587 } else {
588 energy = val;
589 }
590 return 0_J;
591}

References itype::battery, debugmsg, energy, energy_remaining(), is_battery(), and type.

◆ mod_last_rot_check()

void item::mod_last_rot_check ( time_duration  processing_duration)

This is part of a workaround so that items don't rot away to nothing if the smoking rack is outside the reality bubble.

Parameters
processing_duration

Definition at line 5746 of file item.cpp.

5747{
5748 if( !has_own_flag( "PROCESSING" ) ) {
5749 debugmsg( "mod_last_rot_check called on non smoking item: %s", tname() );
5750 return;
5751 }
5752
5753 // Apply no rot while smoking
5754 last_rot_check += processing_duration;
5755}

References debugmsg, has_own_flag(), last_rot_check, and tname().

◆ mod_rot()

void item::mod_rot ( const time_duration val)
inline

Definition at line 863 of file item.h.

863 {
864 rot += val;
865 }

◆ mutations_from_wearing()

std::vector< trait_id > item::mutations_from_wearing ( const Character guy) const

Definition at line 9105 of file item.cpp.

9106{
9107 if( !is_relic() ) {
9108 return std::vector<trait_id> {};
9109 }
9110 std::vector<trait_id> muts;
9111
9112 for( const enchantment &ench : relic_data->get_enchantments() ) {
9113 for( const trait_id &mut : ench.get_mutations() ) {
9114 // this may not be perfectly accurate due to conditions
9115 muts.push_back( mut );
9116 }
9117 }
9118
9119 for( const trait_id &char_mut : guy.get_mutations() ) {
9120 for( auto iter = muts.begin(); iter != muts.end(); ) {
9121 if( char_mut == *iter ) {
9122 iter = muts.erase( iter );
9123 } else {
9124 ++iter;
9125 }
9126 }
9127 }
9128
9129 return muts;
9130}
std::vector< trait_id > get_mutations(bool include_hidden=true) const
Get the idents of all traits/mutations.

References Character::get_mutations(), is_relic(), and relic_data.

Referenced by Character::on_item_takeoff(), and Character::on_item_wear().

◆ needs_processing()

bool item::needs_processing ( ) const

Whether the item should be processed (by calling process).

Definition at line 8951 of file item.cpp.

8952{
8955 is_artifact() || is_food();
8956}
bool needs_processing() const
Whether the item should be processed (by calling process).
Definition: item.cpp:8951
bool is_artifact() const
Definition: item.cpp:6993
static const std::string flag_ETHEREAL_ITEM("ETHEREAL_ITEM")

References active, contents, item_contents::empty(), flag_ETHEREAL_ITEM(), flag_RADIO_ACTIVATION(), item_contents::front(), has_flag(), is_artifact(), is_container(), is_food(), and needs_processing().

Referenced by map::add_item(), vehicle::add_item(), submap::load(), map::make_active(), vehicle::make_active(), needs_processing(), liquid_handler::perform_liquid_transfer(), and Character::process_items().

◆ nname()

std::string item::nname ( const itype_id id,
unsigned int  quantity = 1 
)
static

Returns the translated item name for the item with given id.

The name is in the proper plural form as specified by the quantity parameter. This is roughly equivalent to creating an item instance and calling tname, however this function does not include strings like "(fresh)".

Definition at line 9951 of file item.cpp.

9952{
9953 return id->nname( quantity );
9954}

Referenced by act_vehicle_unload_fuel(), ammo_info(), veh_interact::calc_overview(), camp_car_description(), crafting::can_disassemble(), Character::can_eat(), player::craft_consume_tools(), harvest_list::describe(), veh_interact::display_details(), draw_caravan_items(), spellcasting_callback::draw_spell_info(), farm_action(), activity_handlers::fertilize_plot_do_turn(), final_info(), iexamine::fvat_empty(), plot_options::get_descriptions(), iexamine::get_seed_entries(), plot_options::get_zone_name_suggestion(), repair_item_actor::handle_components(), ammobelt_actor::info(), iexamine::keg(), ma_style_callback::key(), lcmatch_any(), mill_load_food(), iuse::multicooker(), vpart_info::name(), comp_selection< CompType >::nname(), parse_tags(), peek_related_recipe(), activity_handlers::plant_seed_finish(), iexamine::portable_structure(), iexamine::pour_into_keg(), vehicle::print_fuel_indicator(), vehicle::print_part_list(), iexamine::quern_examine(), crafting::query_tool_selection(), avatar_action::reload(), activity_handlers::repair_item_finish(), recipe::result_name(), vehicle::select_engine(), player::select_item_component(), talk_effect_fun_t::set_u_sell_item(), character_funcs::siphon(), smoker_load_food(), iexamine::smoker_options(), vehicle::start_engine(), tname(), tool_comp::to_string(), iexamine::tree_maple(), iexamine::tree_maple_tapped(), try_consume(), unfold_vehicle_iuse::use(), consume_drug_iuse::use(), sew_advanced_actor::use(), and vehicle::use_washing_machine().

◆ on_contents_changed()

void item::on_contents_changed ( )

◆ on_damage()

void item::on_damage ( int  qty,
damage_type  dt 
)

Callback immediately before an item is damaged.

Parameters
qtymaximum damage that will be applied (constrained by max_damage)
dttype of damage (or DT_NULL)

Definition at line 4567 of file item.cpp.

4568{
4569 if( is_corpse() && qty + damage_ >= max_damage() ) {
4571 }
4572}

References damage_, flag_PULPED(), is_corpse(), max_damage(), and set_flag().

Referenced by mod_damage(), and set_damage().

◆ on_drop() [1/2]

bool item::on_drop ( const tripoint pos)

Invokes item type's itype::drop_action.

This function can change the item.

Parameters
posWhere is the item being placed. Note: the item isn't there yet.
Returns
true if the item was destroyed during placement.

Definition at line 10016 of file item.cpp.

10017{
10018 return on_drop( pos, get_map() );
10019}
bool on_drop(const tripoint &pos)
Invokes item type's itype::drop_action.
Definition: item.cpp:10016

References get_map(), and on_drop().

Referenced by map::add_item_or_charges(), and on_drop().

◆ on_drop() [2/2]

bool item::on_drop ( const tripoint pos,
map map 
)

Invokes item type's itype::drop_action.

This function can change the item.

Parameters
posWhere is the item being placed. Note: the item isn't there yet.
mapA map object associated with that position.
Returns
true if the item was destroyed during placement.

Definition at line 10021 of file item.cpp.

10022{
10023 // dropping liquids, even currently frozen ones, on the ground makes them
10024 // dirty
10025 if( made_of( LIQUID ) && !m.has_flag( flag_LIQUIDCONT, pos ) &&
10026 !has_own_flag( "DIRTY" ) ) {
10027 set_flag( "DIRTY" );
10028 }
10029 avatar &you = get_avatar();
10030 you.flag_encumbrance();
10031 return type->drop_action && type->drop_action.call( you, *this, false, pos );
10032}
void flag_encumbrance()
Flag encumbrance for updating.
Definition: character.cpp:1760
static const std::string flag_LIQUIDCONT("LIQUIDCONT")
use_function drop_action
Action to take BEFORE the item is placed on map.
Definition: itype.h:896
int call(player &, item &, bool, const tripoint &) const
Definition: iuse.cpp:9865

References use_function::call(), itype::drop_action, Character::flag_encumbrance(), flag_LIQUIDCONT(), get_avatar(), map::has_flag(), has_own_flag(), LIQUID, made_of(), set_flag(), and type.

◆ on_pickup()

void item::on_pickup ( Character p)

Callback when a player starts carrying the item.

The item is already in the inventory and is called from there. This is not called when the item is added to the inventory from worn vector or weapon slot. The item is considered already carried.

Definition at line 4536 of file item.cpp.

4537{
4538 // Fake characters are used to determine pickup weight and volume
4539 if( p.is_fake() ) {
4540 return;
4541 }
4542 avatar &you = get_avatar();
4543 // TODO: artifacts currently only work with the player character
4544 if( &p == &you && type->artifact ) {
4545 g->add_artifact_messages( type->artifact->effects_carried );
4546 }
4547 // if game is loaded - don't want ownership assigned during char creation
4548 if( you.getID().is_valid() ) {
4550 }
4551 if( is_bucket_nonempty() ) {
4553 }
4554
4555 p.flag_encumbrance();
4556}
virtual bool is_fake() const
Returns true for non-real Creatures used temporarily; i.e.
Definition: creature.cpp:978
bool is_valid() const
Definition: character_id.h:19
bool spill_contents(const tripoint &pos)
void handle_pickup_ownership(Character &c)
Definition: item.cpp:4496
bool is_bucket_nonempty() const
Definition: item.cpp:6770

References itype::artifact, contents, Character::flag_encumbrance(), g, get_avatar(), Character::getID(), handle_pickup_ownership(), is_bucket_nonempty(), Creature::is_fake(), character_id::is_valid(), Character::pos(), item_contents::spill_contents(), and type.

Referenced by Character::i_add().

◆ on_takeoff()

void item::on_takeoff ( Character p)

Callback when a character takes off an item.

The item is still in the worn items vector but will be removed immediately after the function returns

Definition at line 4415 of file item.cpp.

4416{
4417 p.on_item_takeoff( *this );
4418
4419 if( is_sided() ) {
4421 }
4422
4423 // if power armor, no power_draw and active, shut down.
4424 if( type->can_use( "set_transformed" ) && active ) {
4425 const set_transformed_iuse *actor = dynamic_cast<const set_transformed_iuse *>
4426 ( this->get_use( "set_transformed" )->get_actor_ptr() );
4427 if( actor == nullptr ) {
4428 debugmsg( "iuse_actor type descriptor and actual type mismatch" );
4429 return;
4430 }
4431 actor->bypass( *p.as_player(), *this, false, p.pos() );
4432 }
4433}
void on_item_takeoff(const item &it)
Called when an item is taken off.
Definition: character.cpp:9865
virtual player * as_player()
Definition: creature.h:122
bool set_side(side s)
Change the side on which the item is worn.
Definition: item.cpp:818
This is a iuse_transform used by items with transform dependencies.
Definition: iuse_actor.h:350
int bypass(player &p, item &it, bool t, const tripoint &pos) const
Hack: Bypasses normal checks to transform an item.
Definition: iuse_actor.cpp:985

References active, Creature::as_player(), BOTH, set_transformed_iuse::bypass(), itype::can_use(), debugmsg, use_function::get_actor_ptr(), get_use(), is_sided(), Character::on_item_takeoff(), Character::pos(), set_side(), and type.

Referenced by Character::absorb_hit(), Character::i_rem(), and starting_clothes().

◆ on_wear()

void item::on_wear ( Character p)

Callback when a character starts wearing the item.

The item is already in the worn items vector and is called from there.

Definition at line 4317 of file item.cpp.

4318{
4319 if( is_sided() && get_side() == side::BOTH ) {
4320 if( has_flag( flag_SPLINT ) ) {
4322 if( ( covers( bodypart_id( "leg_l" ) ) && p.is_limb_broken( bodypart_id( "leg_r" ) ) &&
4323 !p.worn_with_flag( flag_SPLINT, bodypart_id( "leg_r" ) ) ) ||
4324 ( covers( bodypart_id( "arm_l" ) ) && p.is_limb_broken( bodypart_id( "arm_r" ) ) &&
4325 !p.worn_with_flag( flag_SPLINT, bodypart_id( "arm_r" ) ) ) ) {
4327 }
4328 } else if( has_flag( flag_POWERARMOR_MOD ) ) {
4329 // for power armor mods, wear on side with least mods
4330 std::vector< std::pair< body_part, int > > mod_parts;
4331 body_part bp = num_bp;
4332 bodypart_str_id bpid;
4333 int lhs = 0;
4334 int rhs = 0;
4335 for( std::size_t i = 0; i < static_cast< body_part >( num_bp ) ; ++i ) {
4336 bp = static_cast< body_part >( i );
4337 if( get_covered_body_parts().test( bp ) ) {
4338 mod_parts.emplace_back( bp, 0 );
4339 }
4340 }
4341 for( auto &elem : p.worn ) {
4342 for( std::pair< body_part, int > &mod_part : mod_parts ) {
4343 bpid = convert_bp( mod_part.first );
4344 if( elem.get_covered_body_parts().test( mod_part.first ) &&
4345 elem.has_flag( flag_POWERARMOR_MOD ) ) {
4346 if( elem.is_sided() && elem.get_side() == bpid->part_side ) {
4347 mod_part.second++;
4348 continue;
4349 }
4350 mod_part.second++;
4351 }
4352 }
4353 }
4354 for( std::pair< body_part, int > &mod_part : mod_parts ) {
4355 bpid = convert_bp( mod_part.first );
4356 if( bpid->part_side == side::LEFT && mod_part.second > lhs ) {
4357 add_msg( _( "left" ) );
4358 lhs = mod_part.second;
4359 } else if( bpid->part_side == side::RIGHT && mod_part.second > rhs ) {
4360 add_msg( _( "right" ) );
4361 rhs = mod_part.second;
4362 }
4363 }
4364 set_side( ( lhs > rhs ) ? side::RIGHT : side::LEFT );
4365 } else {
4366 // for sided items wear the item on the side which results in least encumbrance
4367 int lhs = 0;
4368 int rhs = 0;
4370 const char_encumbrance_data left_enc = p.get_encumbrance( *this );
4371 for( const body_part bp : all_body_parts ) {
4372 lhs += left_enc.elems[bp].encumbrance;
4373 }
4374
4376 const char_encumbrance_data right_enc = p.get_encumbrance( *this );
4377 for( const body_part bp : all_body_parts ) {
4378 rhs += right_enc.elems[bp].encumbrance;
4379 }
4380
4381 set_side( lhs <= rhs ? side::LEFT : side::RIGHT );
4382 }
4383 }
4384
4385 if( type->can_use( "set_transformed" ) ) {
4386 bool transform = false;
4387 const set_transformed_iuse *actor = dynamic_cast<const set_transformed_iuse *>
4388 ( this->get_use( "set_transformed" )->get_actor_ptr() );
4389 if( actor == nullptr ) {
4390 debugmsg( "iuse_actor type descriptor and actual type mismatch" );
4391 return;
4392 }
4393 std::string transform_flag = actor->dependencies;
4394 for( const auto &elem : p.worn ) {
4395 if( elem.has_flag( transform_flag ) && elem.active != active ) {
4396 transform = true;
4397 }
4398 }
4399 if( transform && actor->restricted ) {
4400 actor->bypass( *p.as_player(), *this, false, p.pos() );
4401 }
4402 }
4403
4404 // TODO: artifacts currently only work with the player character
4405 if( &p == &get_avatar() && type->artifact ) {
4406 g->add_artifact_messages( type->artifact->effects_worn );
4407 }
4408 // if game is loaded - don't want ownership assigned during char creation
4409 if( get_avatar().getID().is_valid() ) {
4411 }
4412 p.on_item_wear( *this );
4413}
constexpr std::array< body_part, 12 > all_body_parts
Contains all valid body_part values in the order they are defined in.
Definition: bodypart.h:83
body_part
Definition: bodypart.h:40
@ num_bp
Definition: bodypart.h:53
bool worn_with_flag(const std::string &flag, const bodypart_id &bp=bodypart_str_id::NULL_ID()) const
Returns true if the player is wearing an item with the given flag.
Definition: character.cpp:3262
void on_item_wear(const item &it)
Called when an item is worn.
Definition: character.cpp:9850
bool is_limb_broken(const bodypart_id &limb) const
Returns true if the limb is broken.
Definition: character.cpp:1262
char_encumbrance_data get_encumbrance() const
Get encumbrance for all body parts.
Definition: character.cpp:3704
Just like the string_id, this is a wrapper for int based identifiers.
Definition: int_id.h:20
bool restricted
Whether the object can only be transformed externally.
Definition: iuse_actor.h:355
std::string dependencies
String defining flag needed on activating item.
Definition: iuse_actor.h:360
static const std::string flag_SPLINT("SPLINT")
void add_msg(std::string msg)
Definition: messages.cpp:910
side part_side
Definition: bodypart.h:127
std::array< encumbrance_data, num_bp > elems

References _, active, add_msg(), all_body_parts, itype::artifact, Creature::as_player(), BOTH, set_transformed_iuse::bypass(), itype::can_use(), convert_bp(), covers(), debugmsg, set_transformed_iuse::dependencies, char_encumbrance_data::elems, flag_POWERARMOR_MOD(), flag_SPLINT(), g, use_function::get_actor_ptr(), get_avatar(), get_covered_body_parts(), Character::get_encumbrance(), get_side(), get_use(), handle_pickup_ownership(), has_flag(), Character::is_limb_broken(), is_sided(), LEFT, num_bp, Character::on_item_wear(), body_part_type::part_side, Character::pos(), set_transformed_iuse::restricted, RIGHT, set_side(), body_part_set::test(), iexamine::transform(), type, Character::worn, and Character::worn_with_flag().

Referenced by starting_clothes().

◆ on_wield()

void item::on_wield ( player p,
int  mv = 0 
)

Callback when a player starts wielding the item.

The item is already in the weapon slot and is called from there.

Parameters
pplayer that has started wielding item
mvnumber of moves already spent wielding the weapon

Definition at line 4435 of file item.cpp.

4436{
4437 // TODO: artifacts currently only work with the player character
4438 if( &p == &get_avatar() && type->artifact ) {
4439 g->add_artifact_messages( type->artifact->effects_wielded );
4440 }
4441
4442 // weapons with bayonet/bipod or other generic "unhandiness"
4443 if( has_flag( flag_SLOW_WIELD ) && !is_gunmod() ) {
4444 float d = 32.0; // arbitrary linear scaling factor
4445 if( is_gun() ) {
4446 d /= std::max( p.get_skill_level( gun_skill() ), 1 );
4447 } else if( is_melee() ) {
4448 d /= std::max( p.get_skill_level( melee_skill() ), 1 );
4449 }
4450
4451 int penalty = get_var( "volume", volume() / units::legacy_volume_factor ) * d;
4452 p.moves -= penalty;
4453 mv += penalty;
4454 }
4455
4456 // firearms with a folding stock or tool/melee without collapse/retract iuse
4457 if( has_flag( flag_NEEDS_UNFOLD ) && !is_gunmod() ) {
4458 int penalty = 50; // 200-300 for guns, 50-150 for melee, 50 as fallback
4459 if( is_gun() ) {
4460 penalty = std::max( 0, 300 - p.get_skill_level( gun_skill() ) * 10 );
4461 } else if( is_melee() ) {
4462 penalty = std::max( 0, 150 - p.get_skill_level( melee_skill() ) * 10 );
4463 }
4464
4465 p.moves -= penalty;
4466 mv += penalty;
4467 }
4468
4469 std::string msg;
4470
4471 if( mv > 500 ) {
4472 msg = _( "It takes you an extremely long time to wield your %s." );
4473 } else if( mv > 250 ) {
4474 msg = _( "It takes you a very long time to wield your %s." );
4475 } else if( mv > 100 ) {
4476 msg = _( "It takes you a long time to wield your %s." );
4477 } else if( mv > 50 ) {
4478 msg = _( "It takes you several seconds to wield your %s." );
4479 } else {
4480 msg = _( "You wield your %s." );
4481 }
4482 // if game is loaded - don't want ownership assigned during char creation
4483 if( p.getID().is_valid() ) {
4485 }
4486 p.add_msg_if_player( m_neutral, msg, tname() );
4487
4488 if( !p.martial_arts_data->selected_is_none() ) {
4489 p.martial_arts_data->martialart_use_message( p );
4490 }
4491
4492 // Update encumbrance in case we were wearing it
4493 p.flag_encumbrance();
4494}
int moves
Definition: creature.h:582
void add_msg_if_player(const std::string &msg) const override
Definition: player.cpp:366
@ m_neutral
Definition: enums.h:267
static const std::string flag_NEEDS_UNFOLD("NEEDS_UNFOLD")
static const std::string flag_SLOW_WIELD("SLOW_WIELD")

References _, player::add_msg_if_player(), itype::artifact, Character::flag_encumbrance(), flag_NEEDS_UNFOLD(), flag_SLOW_WIELD(), g, get_avatar(), Character::get_skill_level(), get_var(), Character::getID(), gun_skill(), handle_pickup_ownership(), has_flag(), is_gun(), is_gunmod(), is_melee(), character_id::is_valid(), units::legacy_volume_factor, m_neutral, Character::martial_arts_data, melee_skill(), Creature::moves, tname(), type, and volume().

Referenced by character_funcs::try_wield_contents(), and avatar::wield().

◆ only_made_of()

bool item::only_made_of ( const std::set< material_id > &  mat_idents) const

Check we are made of only the materials (e.g.

false if we have one material not in the set or no materials at all).

Parameters
mat_identsSet of material ids.

Definition at line 6472 of file item.cpp.

6473{
6474 const std::vector<material_id> &mats = made_of();
6475 if( mats.empty() ) {
6476 return false;
6477 }
6478
6479 return std::all_of( mats.begin(), mats.end(), [&mat_idents]( const material_id & e ) {
6480 return mat_idents.count( e );
6481 } );
6482}

References made_of().

Referenced by salvage_actor::try_to_cut_up(), and salvage_actor::valid_to_cut_up().

◆ operator<()

bool item::operator< ( const item other) const

Definition at line 7182 of file item.cpp.

7183{
7184 const item_category &cat_a = get_category();
7185 const item_category &cat_b = other.get_category();
7186 if( cat_a != cat_b ) {
7187 return cat_a < cat_b;
7188 } else {
7189 const item *me = is_container() && !contents.empty() ? &contents.front() : this;
7190 const item *rhs = other.is_container() &&
7191 !other.contents.empty() ? &other.contents.front() : &other;
7192
7193 const itype *me_type = me->type;
7194 const itype *rhs_type = rhs->type;
7195 if( !me_type || !rhs_type ) {
7196 return !!me_type;
7197 }
7198
7199 if( me_type->get_id() == rhs_type->get_id() ) {
7200 if( me->is_money() ) {
7201 return me->charges > rhs->charges;
7202 }
7203 return me->charges < rhs->charges;
7204 } else {
7205 std::string n1 = me_type->nname( 1 );
7206 std::string n2 = rhs_type->nname( 1 );
7207 return localized_compare( n1, n2 );
7208 }
7209 }
7210}

References charges, contents, item_contents::empty(), item_contents::front(), get_category(), itype::get_id(), is_container(), is_money(), localized_compare, itype::nname(), other, and type.

◆ operator=() [1/2]

item & item::operator= ( const item )
default

◆ operator=() [2/2]

item & item::operator= ( item &&  )
default

◆ price()

int item::price ( bool  practical) const

Returns the monetary value of an item.

If practical is false, returns pre-cataclysm market value, otherwise returns approximate post-cataclysm value.

Definition at line 4946 of file item.cpp.

4947{
4948 int res = 0;
4949
4950 visit_items( [&res, practical]( const item * e ) {
4951 if( e->rotten() ) {
4952 // TODO: Special case things that stay useful when rotten
4953 return VisitResponse::NEXT;
4954 }
4955
4956 int child = units::to_cent( practical ? e->type->price_post : e->type->price );
4957 if( e->damage() > 0 ) {
4958 // maximal damage level is 4, maximal reduction is 40% of the value.
4959 child -= child * static_cast<double>( e->damage_level( 4 ) ) / 10;
4960 }
4961
4962 if( e->count_by_charges() || e->made_of( LIQUID ) ) {
4963 // price from json data is for default-sized stack
4964 child *= e->charges / static_cast<double>( e->type->stack_size );
4965
4966 } else if( e->magazine_integral() && e->ammo_remaining() && e->ammo_data() ) {
4967 // items with integral magazines may contain ammunition which can affect the price
4968 child += item( e->ammo_data(), calendar::turn, e->charges ).price( practical );
4969
4970 } else if( e->is_tool() && e->ammo_types().empty() && e->ammo_capacity() ) {
4971 // if tool has no ammo (e.g. spray can) reduce price proportional to remaining charges
4972 child *= e->ammo_remaining() / static_cast<double>( std::max( e->type->charges_default(), 1 ) );
4973 }
4974
4975 res += child;
4976 return VisitResponse::NEXT;
4977 } );
4978
4979 return res;
4980}
constexpr value_type to_cent(const quantity< value_type, money_in_cent_tag > &v)
Definition: units_money.h:44
units::money price
Value before cataclysm.
Definition: itype.h:953
units::money price_post
Value after cataclysm, dependent upon practical usages.
Definition: itype.h:955

References ammo_capacity(), ammo_data(), ammo_remaining(), ammo_types(), count_by_charges(), damage(), is_tool(), LIQUID, made_of(), magazine_integral(), NEXT, itype::price, itype::price_post, rotten(), units::to_cent(), type, and visitable< item >::visit_items().

Referenced by talk_function::bionic_install(), talk_function::bionic_remove(), defense_game::caravan(), draw_caravan_items(), talk_function::field_harvest(), final_info(), bionic_install_surgeon_preset::get_money_amount(), npc_trading::init_buying(), npc_trading::init_selling(), parse_tags(), talk_effect_fun_t::set_bulk_trade_accept(), npc::shop_restock(), npc::value(), npc::wants_to_buy(), and npc::wants_to_sell().

◆ process() [1/2]

bool item::process ( player carrier,
const tripoint pos,
bool  activate,
temperature_flag  flag,
const weather_manager weather_generator 
)

Definition at line 9626 of file item.cpp.

9628{
9629 const bool preserves = type->container && type->container->preserves;
9630 const bool seals = type->container && type->container->seals;
9631 std::vector<item *> removed_items;
9632 visit_items( [&]( item * it ) {
9633 if( preserves ) {
9634 // Simulate that the item has already "rotten" up to last_rot_check, but as item::rot
9635 // is not changed, the item is still fresh.
9637 }
9638 if( it->process_internal( carrier, pos, activate, seals, flag, weather_generator ) ) {
9639 removed_items.push_back( it );
9640 }
9641 return VisitResponse::NEXT;
9642 } );
9643 for( item *it : removed_items ) {
9644 if( it != this ) {
9645 remove_item( *it );
9646 }
9647 }
9648 return !removed_items.empty() && std::any_of( removed_items.begin(), removed_items.end(),
9649 [this]( const item * r ) {
9650 return r == this;
9651 } );
9652}
bool process_internal(player *carrier, const tripoint &pos, bool activate, bool seals, temperature_flag flag, const weather_manager &weather_generator)
Definition: item.cpp:9654
item & activate()
Filter converting instance to active state.
Definition: item.cpp:560

References activate(), itype::container, last_rot_check, NEXT, process_internal(), visitable< item >::remove_item(), calendar::turn, type, and visitable< item >::visit_items().

◆ process() [2/2]

bool item::process ( player carrier,
const tripoint pos,
bool  activate,
temperature_flag  flag = temperature_flag::TEMP_NORMAL 
)

This is called once each turn.

It's usually only useful for active items, but can be called for inactive items without problems. It is recursive, and calls process on any contained items.

Parameters
carrierThe player / npc that carries the item. This can be null when the item is not carried by anyone (laying on ground)!
posThe location of the item on the map, same system as player::pos used. If the item is carried, it should be the location of the carrier.
activateWhether the item should be activated (true), or processed as an active item.
Returns
true if the item has been destroyed by the processing. The caller should than delete the item wherever it was stored. Returns false if the item is not destroyed.

Definition at line 9620 of file item.cpp.

9622{
9623 return process( carrier, pos, activate, flag, get_weather() );
9624}
bool process(player *carrier, const tripoint &pos, bool activate, temperature_flag flag=temperature_flag::TEMP_NORMAL)
This is called once each turn.
Definition: item.cpp:9620
weather_manager & get_weather()
Definition: weather.cpp:64

References activate(), get_weather(), and process().

Referenced by map::add_item(), iuse::cable_attach(), drop_or_embed_projectile(), mattack::kamikaze(), process(), vehicle_part::process_contents(), Character::process_items(), and iuse::tow_attach().

◆ process_artifact()

void item::process_artifact ( player carrier,
const tripoint pos 
)

Process and apply artifact effects.

This should be called exactly once each turn, it may modify character stats (like speed, strength, ...), so call it after those have been reset.

Parameters
carrierThe character carrying the artifact, can be null.
posThe location of the artifact (should be the player location if carried).

Definition at line 9090 of file item.cpp.

9091{
9092 if( !is_artifact() ) {
9093 return;
9094 }
9095 // Artifacts are currently only useful for the player character, the messages
9096 // don't consider npcs. Also they are not processed when laying on the ground.
9097 // TODO: change game::process_artifact to work with npcs,
9098 // TODO: consider moving game::process_artifact here.
9099 if( carrier == &get_avatar() ) {
9100 g->process_artifact( *this, *carrier );
9101 }
9102}

References g, get_avatar(), and is_artifact().

Referenced by Character::process_turn().

◆ process_blackpowder_fouling()

bool item::process_blackpowder_fouling ( player carrier)
protected

Definition at line 9609 of file item.cpp.

9610{
9611 if( damage() < max_damage() && one_in( 2000 ) ) {
9613 if( carrier ) {
9614 carrier->add_msg_if_player( m_bad, _( "Your %s rusts due to blackpowder fouling." ), tname() );
9615 }
9616 }
9617 return false;
9618}
@ m_bad
Definition: enums.h:261

References _, player::add_msg_if_player(), damage(), DT_ACID, inc_damage(), m_bad, max_damage(), one_in(), and tname().

Referenced by process_internal().

◆ process_cable()

bool item::process_cable ( player carrier,
const tripoint pos 
)
protected

Definition at line 9391 of file item.cpp.

9392{
9393 if( carrier == nullptr ) {
9394 //reset_cable( carrier );
9395 return false;
9396 }
9397 std::string state = get_var( "state" );
9398 if( state == "solar_pack_link" || state == "solar_pack" ) {
9399 if( !carrier->has_item( *this ) || !carrier->worn_with_flag( "SOLARPACK_ON" ) ) {
9400 carrier->add_msg_if_player( m_bad, _( "You notice the cable has come loose!" ) );
9401 reset_cable( carrier );
9402 return false;
9403 }
9404 }
9405
9406 static const item_filter used_ups = [&]( const item & itm ) {
9407 return itm.get_var( "cable" ) == "plugged_in";
9408 };
9409
9410 if( state == "UPS" ) {
9411 if( !carrier->has_item( *this ) || !carrier->has_item_with( used_ups ) ) {
9412 carrier->add_msg_if_player( m_bad, _( "You notice the cable has come loose!" ) );
9413 for( item *used : carrier->items_with( used_ups ) ) {
9414 used->erase_var( "cable" );
9415 }
9416 reset_cable( carrier );
9417 return false;
9418 }
9419 }
9420 const std::optional<tripoint> source = get_cable_target( carrier, pos );
9421 if( !source ) {
9422 return false;
9423 }
9424 map &here = get_map();
9425 if( !here.veh_at( *source ) || ( source->z != g->get_levz() && !here.has_zlevels() ) ) {
9426 if( carrier->has_item( *this ) ) {
9427 carrier->add_msg_if_player( m_bad, _( "You notice the cable has come loose!" ) );
9428 }
9429 reset_cable( carrier );
9430 return false;
9431 }
9432
9433 int distance = rl_dist( pos, *source );
9434 int max_charges = type->maximum_charges();
9435 charges = max_charges - distance;
9436
9437 if( charges < 1 ) {
9438 if( carrier->has_item( *this ) ) {
9439 carrier->add_msg_if_player( m_bad, _( "The over-extended cable breaks loose!" ) );
9440 }
9441 reset_cable( carrier );
9442 }
9443
9444 return false;
9445}
void reset_cable(player *p)
Helper to bring a cable back to its initial state.
Definition: item.cpp:9447
std::optional< tripoint > get_cable_target(Character *p, const tripoint &pos) const
Gets the point (vehicle tile) the cable is connected to.
Definition: item.cpp:9371
bool has_zlevels() const
Definition: map.h:1635
std::vector< item * > items_with(const std::function< bool(const item &)> &filter)
Returns all items (including those within a container) matching the filter.
Definition: visitable.cpp:324
std::function< bool(const item &)> item_filter
Definition: game.h:119
int maximum_charges() const
Definition: itype.cpp:123

References _, player::add_msg_if_player(), charges, g, get_cable_target(), get_map(), get_var(), visitable< T >::has_item(), visitable< T >::has_item_with(), map::has_zlevels(), visitable< T >::items_with(), m_bad, itype::maximum_charges(), reset_cable(), rl_dist(), type, map::veh_at(), and Character::worn_with_flag().

Referenced by process_internal().

◆ process_corpse()

bool item::process_corpse ( player carrier,
const tripoint pos 
)
protected

Definition at line 9148 of file item.cpp.

9149{
9150 // some corpses rez over time
9151 if( corpse == nullptr || damage() >= max_damage() ) {
9152 return false;
9153 }
9154 if( corpse->zombify_into && rotten() ) {
9155 rot -= get_shelf_life();
9157 return false;
9158 }
9159 if( !ready_to_revive( pos ) ) {
9160 return false;
9161 }
9162 if( rng( 0, volume() / units::legacy_volume_factor ) > burnt && g->revive_corpse( pos, *this ) ) {
9163 if( carrier == nullptr ) {
9164 if( get_avatar().sees( pos ) ) {
9165 if( corpse->in_species( ROBOT ) ) {
9166 add_msg( m_warning, _( "A nearby robot has repaired itself and stands up!" ) );
9167 } else {
9168 add_msg( m_warning, _( "A nearby corpse rises and moves towards you!" ) );
9169 }
9170 }
9171 } else {
9172 if( corpse->in_species( ROBOT ) ) {
9173 carrier->add_msg_if_player( m_warning,
9174 _( "Oh dear god, a robot you're carrying has started moving!" ) );
9175 } else {
9176 carrier->add_msg_if_player( m_warning,
9177 _( "Oh dear god, a corpse you're carrying has started moving!" ) );
9178 }
9179 }
9180 // Destroy this corpse item
9181 return true;
9182 }
9183
9184 return false;
9185}
bool ready_to_revive(const tripoint &pos) const
Whether this corpse should revive now.
Definition: item.cpp:5990
@ m_warning
Definition: enums.h:264
static const species_id ROBOT("ROBOT")
mtype_id zombify_into
Definition: mtype.h:332
bool in_species(const species_id &spec) const
Definition: mtype.cpp:122

References _, add_msg(), player::add_msg_if_player(), burnt, corpse, damage(), g, get_avatar(), get_shelf_life(), mtype::in_species(), units::legacy_volume_factor, m_warning, max_damage(), ready_to_revive(), rng(), ROBOT, rotten(), volume(), and mtype::zombify_into.

Referenced by process_internal().

◆ process_extinguish()

bool item::process_extinguish ( player carrier,
const tripoint pos 
)
protected

Definition at line 9296 of file item.cpp.

9297{
9298 // checks for water
9299 bool extinguish = false;
9300 bool in_inv = carrier != nullptr && carrier->has_item( *this );
9301 bool submerged = false;
9302 bool precipitation = false;
9303 bool windtoostrong = false;
9304 bool in_veh = carrier != nullptr && carrier->in_vehicle;
9305 int windpower = get_weather().windspeed;
9306 switch( get_weather().weather_id->precip ) {
9308 precipitation = one_in( 100 );
9309 break;
9311 precipitation = one_in( 50 );
9312 break;
9314 precipitation = one_in( 10 );
9315 break;
9316 default:
9317 break;
9318 }
9319 map &here = get_map();
9320 if( in_inv && !in_veh && here.has_flag( flag_DEEP_WATER, pos ) ) {
9321 extinguish = true;
9322 submerged = true;
9323 }
9324 if( ( !in_inv && here.has_flag( flag_LIQUID, pos ) && !here.veh_at( pos ) ) ||
9325 ( precipitation && !g->is_sheltered( pos ) ) ) {
9326 extinguish = true;
9327 }
9328 if( in_inv && windpower > 5 && !g->is_sheltered( pos ) &&
9329 this->has_flag( flag_WIND_EXTINGUISH ) ) {
9330 windtoostrong = true;
9331 extinguish = true;
9332 }
9333 if( !extinguish ||
9334 ( in_inv && precipitation && carrier->primary_weapon().has_flag( flag_RAIN_PROTECT ) ) ) {
9335 return false; //nothing happens
9336 }
9337 if( carrier != nullptr ) {
9338 if( submerged ) {
9339 carrier->add_msg_if_player( m_neutral, _( "Your %s is quenched by water." ), tname() );
9340 } else if( precipitation ) {
9341 carrier->add_msg_if_player( m_neutral, _( "Your %s is quenched by precipitation." ),
9342 tname() );
9343 } else if( windtoostrong ) {
9344 carrier->add_msg_if_player( m_neutral, _( "Your %s is blown out by the wind." ),
9345 tname() );
9346 }
9347 }
9348
9349 // cig dies out
9350 if( has_flag( flag_LITCIG ) ) {
9351 if( typeId() == itype_cig_lit ) {
9353 } else if( typeId() == itype_cigar_lit ) {
9355 } else { // joint
9357 }
9358 } else { // transform (lit) items
9359 if( type->tool->revert_to ) {
9360 convert( *type->tool->revert_to );
9361 } else {
9362 type->invoke( carrier != nullptr ? *carrier : get_avatar(), *this, pos, "transform" );
9363 }
9364
9365 }
9366 active = false;
9367 // Item remains
9368 return false;
9369}
bool in_vehicle
Definition: character.h:1573
item & primary_weapon()
Legacy code hack, don't use.
Definition: melee.cpp:166
bool has_flag(const std::string &flag, const tripoint &p) const
Definition: map.cpp:2374
static const itype_id itype_cigar_butt("cigar_butt")
static const itype_id itype_joint_roach("joint_roach")
static const itype_id itype_cig_butt("cig_butt")
static const std::string flag_LIQUID("LIQUID")
static const std::string flag_DEEP_WATER("DEEP_WATER")
static const itype_id itype_cigar_lit("cigar_lit")
static const std::string flag_WIND_EXTINGUISH("WIND_EXTINGUISH")
static const std::string flag_RAIN_PROTECT("RAIN_PROTECT")
static const itype_id itype_cig_lit("cig_lit")
int invoke(player &p, item &it, const tripoint &pos) const
Definition: itype.cpp:180

References _, active, player::add_msg_if_player(), convert(), flag_DEEP_WATER(), flag_LIQUID(), flag_LITCIG(), flag_RAIN_PROTECT(), flag_WIND_EXTINGUISH(), g, get_avatar(), get_map(), get_weather(), has_flag(), map::has_flag(), visitable< T >::has_item(), heavy, Character::in_vehicle, itype::invoke(), itype_cig_butt, itype_cig_lit, itype_cigar_butt, itype_cigar_lit, itype_joint_roach, light, m_neutral, one_in(), Character::primary_weapon(), tname(), itype::tool, type, typeId(), map::veh_at(), very_light, and weather_manager::windspeed.

Referenced by process_internal(), and process_litcig().

◆ process_fake_mill()

bool item::process_fake_mill ( player carrier,
const tripoint pos 
)
protected

Definition at line 9187 of file item.cpp.

9188{
9189 map &here = get_map();
9190 if( here.furn( pos ) != furn_str_id( "f_wind_mill_active" ) &&
9191 here.furn( pos ) != furn_str_id( "f_water_mill_active" ) ) {
9192 item_counter = 0;
9193 return true; //destroy fake mill
9194 }
9195 if( age() >= 6_hours || item_counter == 0 ) {
9197 birthday() ); //activate effects when timers goes to zero
9198 return true; //destroy fake mill item
9199 }
9200
9201 return false;
9202}
furn_id furn(const tripoint &p) const
Definition: map.cpp:1412
void mill_finalize(player &, const tripoint &examp, const time_point &start_time)
Definition: iexamine.cpp:5497

References age(), birthday(), map::furn(), get_avatar(), get_map(), item_counter, and iexamine::mill_finalize().

Referenced by process_internal().

◆ process_fake_smoke()

bool item::process_fake_smoke ( player carrier,
const tripoint pos 
)
protected

Definition at line 9204 of file item.cpp.

9205{
9206 map &here = get_map();
9207 if( here.furn( pos ) != furn_str_id( "f_smoking_rack_active" ) &&
9208 here.furn( pos ) != furn_str_id( "f_metal_smoking_rack_active" ) ) {
9209 item_counter = 0;
9210 return true; //destroy fake smoke
9211 }
9212
9213 if( age() >= 6_hours || item_counter == 0 ) {
9214 iexamine::on_smoke_out( pos, birthday() ); //activate effects when timers goes to zero
9215 return true; //destroy fake smoke when it 'burns out'
9216 }
9217
9218 return false;
9219}
void on_smoke_out(const tripoint &examp, const time_point &start_time)
Definition: iexamine.cpp:5813

References age(), birthday(), map::furn(), get_map(), item_counter, and iexamine::on_smoke_out().

Referenced by process_internal().

◆ process_internal()

bool item::process_internal ( player carrier,
const tripoint pos,
bool  activate,
bool  seals,
temperature_flag  flag,
const weather_manager weather_generator 
)
private

Definition at line 9654 of file item.cpp.

9657{
9658 if( has_flag( flag_ETHEREAL_ITEM ) ) {
9659 if( !has_var( "ethereal" ) ) {
9660 return true;
9661 }
9662 set_var( "ethereal", std::stoi( get_var( "ethereal" ) ) - 1 );
9663 const bool processed = std::stoi( get_var( "ethereal" ) ) <= 0;
9664 if( processed && carrier != nullptr ) {
9665 carrier->add_msg_if_player( _( "Your %s disappears!" ), tname() );
9666 }
9667 return processed;
9668 }
9669
9670 if( faults.count( fault_gun_blackpowder ) ) {
9671 return process_blackpowder_fouling( carrier );
9672 }
9673
9674 avatar &you = get_avatar();
9675 if( activate ) {
9676 return type->invoke( carrier != nullptr ? *carrier : you, *this, pos );
9677 }
9678 // How this works: it checks what kind of processing has to be done
9679 // (e.g. for food, for drying towels, lit cigars), and if that matches,
9680 // call the processing function. If that function returns true, the item
9681 // has been destroyed by the processing, so no further processing has to be
9682 // done.
9683 // Otherwise processing continues. This allows items that are processed as
9684 // food and as litcig and as ...
9685
9686 // Remaining stuff is only done for active items.
9687 if( !active ) {
9688 return false;
9689 }
9690
9691 if( !is_food() && item_counter > 0 ) {
9692 item_counter--;
9693 }
9694
9695 if( item_counter == 0 && type->countdown_action ) {
9696 type->countdown_action.call( carrier ? *carrier : you, *this, false, pos );
9697 if( type->countdown_destroy ) {
9698 return true;
9699 }
9700 }
9701
9702 map &here = get_map();
9703 for( const emit_id &e : type->emits ) {
9704 here.emit_field( pos, e );
9705 }
9706
9707 if( has_flag( flag_FAKE_SMOKE ) && process_fake_smoke( carrier, pos ) ) {
9708 return true;
9709 }
9710 if( has_flag( flag_FAKE_MILL ) && process_fake_mill( carrier, pos ) ) {
9711 return true;
9712 }
9713 if( is_corpse() && process_corpse( carrier, pos ) ) {
9714 return true;
9715 }
9716 if( has_flag( flag_WET ) && process_wet( carrier, pos ) ) {
9717 // Drying items are never destroyed, but we want to exit so they don't get processed as tools.
9718 return false;
9719 }
9720 if( has_flag( flag_LITCIG ) && process_litcig( carrier, pos ) ) {
9721 return true;
9722 }
9724 process_extinguish( carrier, pos ) ) {
9725 return false;
9726 }
9727 if( has_flag( flag_CABLE_SPOOL ) ) {
9728 // DO NOT process this as a tool! It really isn't!
9729 return process_cable( carrier, pos );
9730 }
9731 if( has_flag( flag_IS_UPS ) ) {
9732 // DO NOT process this as a tool! It really isn't!
9733 return process_UPS( carrier, pos );
9734 }
9735 if( is_tool() ) {
9736 return process_tool( carrier, pos );
9737 }
9738 // All foods that go bad have temperature
9739 if( ( is_food() || is_corpse() ) &&
9740 process_rot( seals, pos, carrier, flag, weather_generator ) ) {
9741 if( is_comestible() ) {
9742 here.rotten_item_spawn( *this, pos );
9743 }
9744 return true;
9745 }
9746
9747 return false;
9748}
bool process_fake_mill(player *carrier, const tripoint &pos)
Definition: item.cpp:9187
bool process_UPS(player *carrier, const tripoint &pos)
Definition: item.cpp:9464
bool process_corpse(player *carrier, const tripoint &pos)
Definition: item.cpp:9148
bool process_wet(player *carrier, const tripoint &pos)
Definition: item.cpp:9482
bool process_blackpowder_fouling(player *carrier)
Definition: item.cpp:9609
bool process_litcig(player *carrier, const tripoint &pos)
Definition: item.cpp:9221
bool process_extinguish(player *carrier, const tripoint &pos)
Definition: item.cpp:9296
bool process_fake_smoke(player *carrier, const tripoint &pos)
Definition: item.cpp:9204
bool process_tool(player *carrier, const tripoint &pos)
Definition: item.cpp:9495
bool process_cable(player *carrier, const tripoint &pos)
Definition: item.cpp:9391
void emit_field(const tripoint &pos, const emit_id &src, float mul=1.0f)
Runs one cycle of emission src which may result in propagation of fields.
Definition: map_field.cpp:1927
void rotten_item_spawn(const item &item, const tripoint &p)
Checks to see if the item that is rotting away generates a creature when it does.
Definition: map.cpp:7236
static const std::string flag_WATER_EXTINGUISH("WATER_EXTINGUISH")
static const std::string flag_CABLE_SPOOL("CABLE_SPOOL")
static const fault_id fault_gun_blackpowder("fault_gun_blackpowder")
static const std::string flag_IS_UPS("IS_UPS")
static const std::string flag_FAKE_MILL("FAKE_MILL")
static const std::string flag_FAKE_SMOKE("FAKE_SMOKE")
use_function countdown_action
Action to take when countdown expires.
Definition: itype.h:924
bool countdown_destroy
Is item destroyed after the countdown action is run?
Definition: itype.h:918
std::set< emit_id > emits
Fields to emit when item is in active state.
Definition: itype.h:899

References _, activate(), active, player::add_msg_if_player(), use_function::call(), itype::countdown_action, itype::countdown_destroy, map::emit_field(), itype::emits, fault_gun_blackpowder, faults, flag_CABLE_SPOOL(), flag_ETHEREAL_ITEM(), flag_FAKE_MILL(), flag_FAKE_SMOKE(), flag_IS_UPS(), flag_LITCIG(), flag_WATER_EXTINGUISH(), flag_WET(), flag_WIND_EXTINGUISH(), get_avatar(), get_map(), get_var(), has_flag(), has_var(), itype::invoke(), is_comestible(), is_corpse(), is_food(), is_tool(), item_counter, process_blackpowder_fouling(), process_cable(), process_corpse(), process_extinguish(), process_fake_mill(), process_fake_smoke(), process_litcig(), process_rot(), process_tool(), process_UPS(), process_wet(), map::rotten_item_spawn(), set_var(), tname(), and type.

Referenced by process().

◆ process_litcig()

bool item::process_litcig ( player carrier,
const tripoint pos 
)
protected

Definition at line 9221 of file item.cpp.

9222{
9223 if( !one_in( 10 ) ) {
9224 return false;
9225 }
9226 process_extinguish( carrier, pos );
9227 // process_extinguish might have extinguished the item already
9228 if( !active ) {
9229 return false;
9230 }
9231 map &here = get_map();
9232 // if carried by someone:
9233 if( carrier != nullptr ) {
9234 time_duration duration = 15_seconds;
9235 if( carrier->has_trait( trait_TOLERANCE ) ) {
9236 duration = 7_seconds;
9237 } else if( carrier->has_trait( trait_LIGHTWEIGHT ) ) {
9238 duration = 30_seconds;
9239 }
9240 carrier->add_msg_if_player( m_neutral, _( "You take a puff of your %s." ), tname() );
9241 if( has_flag( flag_TOBACCO ) ) {
9242 carrier->add_effect( effect_cig, duration );
9243 } else {
9244 carrier->add_effect( effect_weed_high, duration / 2 );
9245 }
9246 carrier->moves -= 15;
9247
9248 if( ( carrier->has_effect( effect_shakes ) && one_in( 10 ) ) ) {
9249 carrier->add_msg_if_player( m_bad, _( "Your shaking hand causes you to drop your %s." ),
9250 tname() );
9251 here.add_item_or_charges( pos + point( rng( -1, 1 ), rng( -1, 1 ) ), *this );
9252 return true; // removes the item that has just been added to the map
9253 }
9254
9255 if( carrier->has_effect( effect_sleep ) ) {
9256 carrier->add_msg_if_player( m_bad, _( "You fall asleep and drop your %s." ),
9257 tname() );
9258 here.add_item_or_charges( pos + point( rng( -1, 1 ), rng( -1, 1 ) ), *this );
9259 return true; // removes the item that has just been added to the map
9260 }
9261 } else {
9262 // If not carried by someone, but laying on the ground:
9263 if( item_counter % 5 == 0 ) {
9264 // lit cigarette can start fires
9265 if( here.flammable_items_at( pos ) ||
9266 here.has_flag( flag_FLAMMABLE, pos ) ||
9267 here.has_flag( flag_FLAMMABLE_ASH, pos ) ) {
9268 here.add_field( pos, fd_fire, 1 );
9269 }
9270 }
9271 }
9272
9273 // cig dies out
9274 if( item_counter == 0 ) {
9275 if( carrier != nullptr ) {
9276 carrier->add_msg_if_player( m_neutral, _( "You finish your %s." ), tname() );
9277 }
9278 if( typeId() == itype_cig_lit ) {
9280 } else if( typeId() == itype_cigar_lit ) {
9282 } else { // joint
9284 if( carrier != nullptr ) {
9285 carrier->add_effect( effect_weed_high, 1_minutes ); // one last puff
9286 here.add_field( pos + point( rng( -1, 1 ), rng( -1, 1 ) ), fd_weedsmoke, 2 );
9287 weed_msg( *carrier );
9288 }
9289 }
9290 active = false;
9291 }
9292 // Item remains
9293 return false;
9294}
void add_effect(const effect &eff, bool force=false, bool deferred=false)
Definition: creature.cpp:988
bool has_effect(const efftype_id &eff_id, body_part bp=num_bp) const
Check if creature has the matching effect.
Definition: creature.cpp:1187
bool add_field(const tripoint &p, const field_type_id &type_id, int intensity=INT_MAX, const time_duration &age=0_turns, bool hit_player=true)
Add field entry at point, or set intensity if present.
Definition: map.cpp:5528
item & add_item_or_charges(const tripoint &pos, item obj, bool overflow=true)
Adds an item to map tile or stacks charges.
Definition: map.cpp:4354
bool flammable_items_at(const tripoint &p, int threshold=0)
Checks if there are any flammable items on the tile.
Definition: map.cpp:2687
void weed_msg(player &p)
Handles the large variety of weed messages.
Definition: effect.cpp:78
field_type_id fd_fire
Definition: field_type.cpp:345
field_type_id fd_weedsmoke
Definition: field_type.cpp:368
static const efftype_id effect_weed_high("weed_high")
static const trait_id trait_TOLERANCE("TOLERANCE")
static const trait_id trait_LIGHTWEIGHT("LIGHTWEIGHT")
static const std::string flag_FLAMMABLE("FLAMMABLE")
static const efftype_id effect_cig("cig")
static const efftype_id effect_sleep("sleep")
static const std::string flag_FLAMMABLE_ASH("FLAMMABLE_ASH")
static const std::string flag_TOBACCO("TOBACCO")
static const efftype_id effect_shakes("shakes")
Definition: point.h:35

References _, active, Creature::add_effect(), map::add_field(), map::add_item_or_charges(), player::add_msg_if_player(), convert(), effect_cig, effect_shakes, effect_sleep, effect_weed_high, fd_fire, fd_weedsmoke, flag_FLAMMABLE(), flag_FLAMMABLE_ASH(), flag_TOBACCO(), map::flammable_items_at(), get_map(), Creature::has_effect(), has_flag(), map::has_flag(), Character::has_trait(), item_counter, itype_cig_butt, itype_cig_lit, itype_cigar_butt, itype_cigar_lit, itype_joint_roach, m_bad, m_neutral, Creature::moves, one_in(), process_extinguish(), rng(), tname(), trait_LIGHTWEIGHT, trait_TOLERANCE, typeId(), and weed_msg().

Referenced by process_internal().

◆ process_relic()

void item::process_relic ( Character carrier)

Definition at line 9132 of file item.cpp.

9133{
9134 if( !is_relic() ) {
9135 return;
9136 }
9137 std::vector<enchantment> active_enchantments;
9138
9139 for( const enchantment &ench : get_enchantments() ) {
9140 if( ench.is_active( carrier, *this ) ) {
9141 active_enchantments.emplace_back( ench );
9142 }
9143 }
9144
9145 relic_funcs::process_recharge( *this, carrier );
9146}
void process_recharge(item &itm, Character &carrier)
Definition: relic.cpp:449

References get_enchantments(), is_relic(), and relic_funcs::process_recharge().

Referenced by Character::process_turn().

◆ process_rot() [1/2]

bool item::process_rot ( bool  seals,
const tripoint pos,
player carrier,
temperature_flag  flag,
const weather_manager weather_generator 
)

Definition at line 8995 of file item.cpp.

8998{
8999 const time_point now = calendar::turn;
9000
9001 // if player debug menu'd the time backward it breaks stuff, just reset the
9002 // last_temp_check and last_rot_check in this case
9003 if( now - last_rot_check < 0_turns ) {
9004 last_rot_check = now;
9005 return false;
9006 }
9007
9008 // process rot at most once every 100_turns (10 min)
9009 // note we're also gated by item::processing_speed
9010 time_duration smallest_interval = 10_minutes;
9011
9012 units::temperature temp = units::from_fahrenheit( weather.get_temperature( pos ) );
9013 temp = clip_by_temperature_flag( temp, flag );
9014
9017
9018 if( now - time > 1_hours ) {
9019 // This code is for items that were left out of reality bubble for long time
9020
9021 const weather_generator &wgen = weather.get_cur_weather_gen();
9022 const unsigned int seed = g->get_seed();
9023 // It's a modifier, so we need to subtract 0_f
9024 units::temperature local_mod = units::from_fahrenheit( g->new_game
9025 ? 0
9026 : get_map().get_temperature( pos ) ) - 0_f;
9027
9028 // Process the past of this item since the last time it was processed
9029 while( now - time > 1_hours ) {
9030 // Get the environment temperature
9031 time_duration time_delta = std::min( 1_hours, now - 1_hours - time );
9032 time += time_delta;
9033
9034 //Use weather if above ground, use map temp if below
9035 units::temperature env_temperature_raw;
9036 if( pos.z >= 0 ) {
9037 tripoint_abs_ms location = tripoint_abs_ms( get_map().getabs( pos ) );
9038 units::temperature weather_temperature = wgen.get_weather_temperature( location, time,
9040 env_temperature_raw = weather_temperature + local_mod;
9041 } else {
9042 env_temperature_raw = units::from_fahrenheit( AVERAGE_ANNUAL_TEMPERATURE ) + local_mod;
9043 }
9044
9045 units::temperature env_temperature_clipped = clip_by_temperature_flag( env_temperature_raw, flag );
9046
9047 // Lookup table is in F
9048 int final_temperature_in_fahrenheit = static_cast<int>( std::round( units::to_fahrenheit<float>
9049 ( env_temperature_clipped ) ) );
9050
9051 // Calculate item rot
9052 rot += calc_rot( time, final_temperature_in_fahrenheit );
9054
9055 if( has_rotten_away() && carrier == nullptr && !seals ) {
9056 // No need to track item that will be gone
9057 return true;
9058 }
9059 }
9060 }
9061
9062 // Remaining <1 h from above
9063 // and items that are held near the player
9064 if( now - time > smallest_interval ) {
9065 int final_temperature_in_fahrenheit = static_cast<int>( std::round( units::to_fahrenheit<float>
9066 ( temp ) ) );
9067
9068 rot += calc_rot( now, final_temperature_in_fahrenheit );
9069 last_rot_check = now;
9070
9071 return has_rotten_away() && carrier == nullptr && !seals;
9072 }
9073 // If we're still here, mark how cold it is so we can apply tagtext to items
9074 // FIXME: this might cause issues with performance, move the comparision
9075 // directly to item::tname once #2250 lands
9076 if( temp <= temperatures::freezing ) {
9079 } else if( temp <= temperatures::root_cellar ) {
9082 } else {
9085 }
9086
9087 return false;
9088}
time_duration calc_rot(time_point time, int temp) const
Returns rot of the item since last rot calculation.
Definition: item.cpp:5676
bool has_rotten_away() const
Whether the item has enough rot that it should get removed.
Definition: item.cpp:8811
A point in the game time.
Definition: calendar.h:431
units::temperature get_weather_temperature(const tripoint_abs_ms &, const time_point &, const calendar_config &calendar_config, unsigned) const
coords::coord_point< tripoint, coords::origin::abs, coords::ms > tripoint_abs_ms
Definition: coordinates.h:486
static constexpr int AVERAGE_ANNUAL_TEMPERATURE
Average annual temperature in F used for climate, weather and temperature calculation.
static units::temperature clip_by_temperature_flag(units::temperature temperature, temperature_flag flag)
Definition: item.cpp:8972
static const std::string flag_VERY_COLD("VERY_COLD")
static const std::string flag_COLD("COLD")
calendar_config config
int seed(player *, item *, bool, const tripoint &)
Definition: iuse.cpp:6013
constexpr units::temperature freezing
constexpr units::temperature root_cellar
constexpr quantity< value_type, temperature_in_millidegree_celsius_tag > from_fahrenheit(const value_type v)
int z
Definition: point.h:138

References AVERAGE_ANNUAL_TEMPERATURE, calc_rot(), clip_by_temperature_flag(), calendar::config, flag_COLD(), flag_VERY_COLD(), temperatures::freezing, units::from_fahrenheit(), g, get_map(), weather_generator::get_weather_temperature(), has_rotten_away(), last_rot_check, temperatures::root_cellar, iuse::seed(), set_flag(), time, calendar::turn, unset_flag(), and tripoint::z.

◆ process_rot() [2/2]

bool item::process_rot ( const tripoint pos)

Update temperature for things like food Update rot for things that perish All items that rot also have temperature.

Parameters
sealsWether the item is in sealed container
posThe current position
carrierThe current carrier
flagto specify special temperature situations
weather_generatorweather manager, mostly for testing
Returns
true if the item is fully rotten and is ready to be removed

Definition at line 8967 of file item.cpp.

8968{
8969 return process_rot( false, pos, nullptr, temperature_flag::TEMP_NORMAL, get_weather() );
8970}

References get_weather(), process_rot(), and TEMP_NORMAL.

Referenced by actualize_rot(), process_internal(), and process_rot().

◆ process_tool()

bool item::process_tool ( player carrier,
const tripoint pos 
)
protected

Definition at line 9495 of file item.cpp.

9496{
9497 avatar &you = get_avatar();
9498 // items with iuse set_transformed which are restricted turn off if not attached to their dependency.
9499 if( type->can_use( "set_transformed" ) ) {
9500 const set_transformed_iuse *actor = dynamic_cast<const set_transformed_iuse *>
9501 ( this->get_use( "set_transformed" )->get_actor_ptr() );
9502 if( actor == nullptr ) {
9503 debugmsg( "iuse_actor type descriptor and actual type mismatch" );
9504 return false;
9505 }
9506 if( actor->restricted ) {
9507 if( !carrier ) {
9508 actor->bypass( carrier != nullptr ? *carrier : you, *this, false, pos );
9509 return false;
9510 } else {
9511 bool active = false;
9512 std::string transform_flag = actor->dependencies;
9513 for( const auto &elem : carrier->worn ) {
9514 if( elem.active && elem.has_flag( transform_flag ) ) {
9515 active = true;
9516 break;
9517 }
9518 }
9519 if( !active ) {
9520 actor->bypass( carrier != nullptr ? *carrier : you, *this, false, pos );
9521 return false;
9522 }
9523 }
9524 }
9525 }
9526
9527 int energy = 0;
9528 if( type->tool->turns_per_charge > 0 &&
9529 to_turn<int>( calendar::turn ) % type->tool->turns_per_charge == 0 ) {
9530 energy = std::max( ammo_required(), 1 );
9531
9532 } else if( type->tool->power_draw > 0 ) {
9533 // power_draw in mW / 1000000 to give kJ (battery unit) per second
9534 energy = type->tool->power_draw / 1000000;
9535 // energy_bat remainder results in chance at additional charge/discharge
9536 energy += x_in_y( type->tool->power_draw % 1000000, 1000000 ) ? 1 : 0;
9537 }
9538 energy -= ammo_consume( energy, pos );
9539
9540 // for power armor pieces, try to use power armor interface first.
9541 if( carrier && is_power_armor() && character_funcs::can_interface_armor( *carrier ) ) {
9542 if( carrier->use_charges_if_avail( itype_bio_armor, energy ) ) {
9543 energy = 0;
9544 }
9545 }
9546
9547 // for items in player possession if insufficient charges within tool try UPS
9548 if( carrier && ( has_flag( flag_USE_UPS ) ) ) {
9549 if( carrier->use_charges_if_avail( itype_UPS, energy ) ) {
9550 energy = 0;
9551 }
9552 }
9553
9554 // if insufficient available charges shutdown the tool
9555 if( energy > 0 ) {
9556 if( carrier ) {
9557 if( is_power_armor() ) {
9558 if( has_flag( flag_USE_UPS ) ) {
9559 carrier->add_msg_if_player( m_info, _( "You need a UPS or Bionic Power Interface to run the %s!" ),
9560 tname() );
9561 } else {
9562 carrier->add_msg_if_player( m_info, _( "You need a Bionic Power Interface to run the %s!" ),
9563 tname() );
9564 }
9565 } else if( has_flag( flag_USE_UPS ) ) {
9566 carrier->add_msg_if_player( m_info, _( "You need a UPS to run the %s!" ), tname() );
9567 }
9568 }
9569 if( carrier && type->can_use( "set_transform" ) ) {
9570 const set_transform_iuse *actor = dynamic_cast<const set_transform_iuse *>
9571 ( this->get_use( "set_transform" )->get_actor_ptr() );
9572 if( actor == nullptr ) {
9573 debugmsg( "iuse_actor type descriptor and actual type mismatch." );
9574 return false;
9575 }
9576 std::string transformed_flag = actor->flag;
9577 for( auto &elem : carrier->worn ) {
9578 if( elem.active && elem.has_flag( transformed_flag ) ) {
9579 if( !elem.type->can_use( "set_transformed" ) ) {
9580 debugmsg( "Expected set_transformed function" );
9581 return false;
9582 }
9583 const set_transformed_iuse *actor = dynamic_cast<const set_transformed_iuse *>
9584 ( elem.get_use( "set_transformed" )->get_actor_ptr() );
9585 if( actor == nullptr ) {
9586 debugmsg( "iuse_actor type descriptor and actual type mismatch" );
9587 return false;
9588 }
9589 actor->bypass( *carrier, elem, false, pos );
9590 }
9591 }
9592 }
9593
9594 // invoking the object can convert the item to another type
9595 const bool had_revert_to = type->tool->revert_to.has_value();
9596 type->invoke( carrier != nullptr ? *carrier : you, *this, pos );
9597 if( had_revert_to ) {
9598 deactivate( carrier );
9599 return false;
9600 } else {
9601 return true;
9602 }
9603 }
9604
9605 type->tick( carrier != nullptr ? *carrier : you, *this, pos );
9606 return false;
9607}
bool use_charges_if_avail(const itype_id &it, int quantity)
Definition: character.cpp:9650
item & deactivate(const Character *ch=nullptr, bool alert=true)
Filter converting this instance to the inactive type If the item is either inactive or cannot be deac...
Definition: item.cpp:543
This is a iuse_transform that changes a set of items with a specific flag.
Definition: iuse_actor.h:318
std::string flag
Flag string so we know what the heck we're transforming.
Definition: iuse_actor.h:328
static const itype_id itype_UPS("UPS")
static const itype_id itype_bio_armor("bio_armor")
bool can_interface_armor(const Character &who)
Check whether character has an active bionic capable of interfacing with power armor.
void tick(player &p, item &it, const tripoint &pos) const
Definition: itype.cpp:172

References _, active, player::add_msg_if_player(), ammo_consume(), ammo_required(), set_transformed_iuse::bypass(), character_funcs::can_interface_armor(), itype::can_use(), deactivate(), debugmsg, set_transformed_iuse::dependencies, energy, set_transform_iuse::flag, flag_USE_UPS(), use_function::get_actor_ptr(), get_avatar(), get_use(), has_flag(), itype::invoke(), is_power_armor(), itype_bio_armor, itype_UPS, m_info, set_transformed_iuse::restricted, itype::tick(), tname(), itype::tool, calendar::turn, type, Character::use_charges_if_avail(), Character::worn, and x_in_y().

Referenced by process_internal().

◆ process_UPS()

bool item::process_UPS ( player carrier,
const tripoint pos 
)
protected

Definition at line 9464 of file item.cpp.

9465{
9466 if( carrier == nullptr ) {
9467 erase_var( "cable" );
9468 active = false;
9469 return false;
9470 }
9471 bool has_connected_cable = carrier->has_item_with( []( const item & it ) {
9472 return it.active && it.has_flag( flag_CABLE_SPOOL ) && ( it.get_var( "state" ) == "UPS_link" ||
9473 it.get_var( "state" ) == "UPS" );
9474 } );
9475 if( !has_connected_cable ) {
9476 erase_var( "cable" );
9477 active = false;
9478 }
9479 return false;
9480}

References active, erase_var(), flag_CABLE_SPOOL(), get_var(), has_flag(), and visitable< T >::has_item_with().

Referenced by process_internal().

◆ process_wet()

bool item::process_wet ( player carrier,
const tripoint pos 
)
protected

Definition at line 9482 of file item.cpp.

9483{
9484 if( item_counter == 0 ) {
9485 if( is_tool() && type->tool->revert_to ) {
9486 convert( *type->tool->revert_to );
9487 }
9488 unset_flag( "WET" );
9489 active = false;
9490 }
9491 // Always return true so our caller will bail out instead of processing us as a tool.
9492 return true;
9493}

References active, convert(), is_tool(), item_counter, itype::tool, type, and unset_flag().

Referenced by process_internal().

◆ processing_speed()

int item::processing_speed ( ) const

The rate at which an item should be processed, in number of turns between updates.

Definition at line 8958 of file item.cpp.

8959{
8960 if( is_corpse() || is_food() || is_food_container() ) {
8961 return to_turns<int>( 10_minutes );
8962 }
8963 // Unless otherwise indicated, update every turn.
8964 return 1;
8965}

References is_corpse(), is_food(), and is_food_container().

Referenced by active_item_cache::add().

◆ put_in()

◆ qualities_info()

void item::qualities_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3248 of file item.cpp.

3250{
3251 auto name_quality = [&info]( const std::pair<quality_id, int> &q ) {
3252 std::string str;
3253 if( q.first == qual_JACK || q.first == qual_LIFT ) {
3254 str = string_format( _( "Has level <info>%1$d %2$s</info> quality and "
3255 "is rated at <info>%3$d</info> %4$s" ),
3256 q.second, q.first.obj().name,
3257 static_cast<int>( convert_weight( q.second * TOOL_LIFT_FACTOR ) ),
3258 weight_units() );
3259 } else {
3260 str = string_format( _( "Has level <info>%1$d %2$s</info> quality." ),
3261 q.second, q.first.obj().name );
3262 }
3263 info.emplace_back( "QUALITIES", "", str );
3264 };
3265
3266 if( parts->test( iteminfo_parts::QUALITIES ) ) {
3268 for( const std::pair<const quality_id, int> q : sorted_lex( type->qualities ) ) {
3269 name_quality( q );
3270 }
3271 }
3272
3274 contents.has_any_with( []( const item & e ) {
3275 return !e.type->qualities.empty();
3276 } ) ) {
3277
3278 info.emplace_back( "QUALITIES", "", _( "Contains items with qualities:" ) );
3279 std::map<quality_id, int, quality_id::LexCmp> most_quality;
3280 for( const item *e : contents.all_items_top() ) {
3281 for( const std::pair<const quality_id, int> &q : e->type->qualities ) {
3282 auto emplace_result = most_quality.emplace( q );
3283 if( !emplace_result.second &&
3284 most_quality.at( emplace_result.first->first ) < q.second ) {
3285 most_quality[ q.first ] = q.second;
3286 }
3287 }
3288 }
3289 for( const std::pair<const quality_id, int> &q : most_quality ) {
3290 name_quality( q );
3291 }
3292 }
3293}
bool has_any_with(const std::function< bool(const item &)> &filter) const
#define TOOL_LIFT_FACTOR
static const quality_id qual_JACK("JACK")
static const quality_id qual_LIFT("LIFT")

References _, item_contents::all_items_top(), contents, convert_weight(), item_contents::has_any_with(), info(), insert_separation_line(), qual_JACK, qual_LIFT, QUALITIES, itype::qualities, QUALITIES_CONTAINED, sorted_lex(), string_format(), iteminfo_query::test(), TOOL_LIFT_FACTOR, type, and weight_units().

Referenced by info().

◆ quality_of()

const std::map< quality_id, int > & item::quality_of ( ) const

The ids of all the qualities this contains.

Definition at line 6446 of file item.cpp.

6447{
6448 return type->qualities;
6449}

References itype::qualities, and type.

◆ reach_range()

int item::reach_range ( const Character guy) const

Max range of melee attack this weapon can be used for.

Accounts for character's abilities and installed gun mods. Guaranteed to be at least 1

Definition at line 5290 of file item.cpp.

5291{
5292 int res = 1;
5293
5294 if( has_flag( flag_REACH_ATTACK ) ) {
5295 res = has_flag( flag_REACH3 ) ? 3 : 2;
5296 }
5297
5298 // for guns consider any attached gunmods
5299 if( is_gun() && !is_gunmod() ) {
5300 for( const std::pair<const gun_mode_id, gun_mode> &m : gun_all_modes() ) {
5301 if( guy.is_npc() && m.second.flags.count( "NPC_AVOID" ) ) {
5302 continue;
5303 }
5304 if( m.second.melee() ) {
5305 res = std::max( res, m.second.qty );
5306 }
5307 }
5308 }
5309
5310 return std::max( 1, res );
5311}
virtual bool is_npc() const
Definition: creature.h:98

References flag_REACH3(), flag_REACH_ATTACK(), gun_all_modes(), has_flag(), is_gun(), is_gunmod(), and Creature::is_npc().

Referenced by avatar_action::autoattack(), fire(), npc::invalidate_range_cache(), Character::melee_attack(), npc_ai::melee_value(), npc::method_of_attack(), and target_handler::mode_reach().

◆ ready_to_revive()

bool item::ready_to_revive ( const tripoint pos) const

Whether this corpse should revive now.

Note that this function includes some randomness, the return value can differ on successive calls.

Parameters
posThe location of the item (see REVIVE_SPECIAL flag).

Definition at line 5990 of file item.cpp.

5991{
5992 if( !can_revive() ) {
5993 return false;
5994 }
5995 if( get_map().veh_at( pos ) ) {
5996 return false;
5997 }
5998 if( !calendar::once_every( 1_seconds ) ) {
5999 return false;
6000 }
6001 int age_in_hours = to_hours<int>( age() );
6002 age_in_hours -= static_cast<int>( static_cast<float>( burnt ) / ( volume() / 250_ml ) );
6003 if( damage_level( 4 ) > 0 ) {
6004 age_in_hours /= ( damage_level( 4 ) + 1 );
6005 }
6006 int rez_factor = 48 - age_in_hours;
6007 if( age_in_hours > 6 && ( rez_factor <= 0 || one_in( rez_factor ) ) ) {
6008 // If we're a special revival zombie, wait to get up until the player is nearby.
6009 const bool isReviveSpecial = has_flag( flag_REVIVE_SPECIAL );
6010 if( isReviveSpecial ) {
6011 const int distance = rl_dist( pos, get_player_character().pos() );
6012 if( distance > 3 ) {
6013 return false;
6014 }
6015 if( !one_in( distance + 1 ) ) {
6016 return false;
6017 }
6018 }
6019
6020 return true;
6021 }
6022 return false;
6023}
static const std::string flag_REVIVE_SPECIAL("REVIVE_SPECIAL")
bool once_every(const time_duration &event_frequency)
Predicate to handle rate-limiting.
Definition: calendar.cpp:490

References age(), burnt, can_revive(), damage_level(), flag_REVIVE_SPECIAL(), get_map(), get_player_character(), has_flag(), calendar::once_every(), one_in(), rl_dist(), and volume().

Referenced by process_corpse().

◆ reinforceable()

bool item::reinforceable ( ) const

Whether the item can be repaired beyond normal health.

Definition at line 6524 of file item.cpp.

6525{
6526 if( is_null() || has_flag( flag_NO_REPAIR ) ) {
6527 return false;
6528 }
6529
6530 // If a material is reinforceable, so are we
6531 const std::vector<const material_type *> &mats = made_of_types();
6532 return std::any_of( mats.begin(), mats.end(), []( const material_type * mt ) {
6533 return mt->reinforces();
6534 } );
6535}
static const std::string flag_NO_REPAIR("NO_REPAIR")

References flag_NO_REPAIR(), has_flag(), is_null(), and made_of_types().

Referenced by repair_item_actor::can_repair_target(), repair_item_actor::repair(), and repair_info().

◆ release_monster()

bool item::release_monster ( const tripoint target,
int  radius = 0 
)

Definition at line 9238 of file iuse.cpp.

9239{
9240 shared_ptr_fast<monster> new_monster = make_shared_fast<monster>();
9241 try {
9242 ::deserialize( *new_monster, get_var( "contained_json", "" ) );
9243 } catch( const std::exception &e ) {
9244 debugmsg( _( "Error restoring monster: %s" ), e.what() );
9245 return false;
9246 }
9247 if( !g->place_critter_around( new_monster, target, radius ) ) {
9248 return false;
9249 }
9250 erase_var( "contained_name" );
9251 erase_var( "contained_json" );
9252 erase_var( "name" );
9253 erase_var( "weight" );
9254 return true;
9255}
void deserialize(JsonIn &jsin)
std::shared_ptr< T > shared_ptr_fast
Definition: memory_fast.h:16

References _, debugmsg, deserialize(), erase_var(), g, and get_var().

Referenced by iuse::capture_monster_act(), and DefaultRemovePartHandler::spawn_animal_from_part().

◆ reload()

bool item::reload ( player u,
item_location  loc,
int  qty 
)

Reload item using ammo from location returning true if successful.

Parameters
uPlayer doing the reloading
locLocation of ammo to be reloaded
qtycaps reloading to this (or fewer) units

Definition at line 8127 of file item.cpp.

8128{
8129 if( qty <= 0 ) {
8130 debugmsg( "Tried to reload zero or less charges" );
8131 return false;
8132 }
8133 item *ammo = loc.get_item();
8134 if( ammo == nullptr || ammo->is_null() ) {
8135 debugmsg( "Tried to reload using non-existent ammo" );
8136 return false;
8137 }
8138
8139 item *container = nullptr;
8140 if( ammo->is_ammo_container() || ammo->is_container() ) {
8141 container = ammo;
8142 ammo = &ammo->contents.front();
8143 }
8144
8145 if( !is_reloadable_with( ammo->typeId() ) ) {
8146 return false;
8147 }
8148
8149 // limit quantity of ammo loaded to remaining capacity
8150 int limit = is_watertight_container()
8153
8154 if( ammo->ammo_type() == ammo_plutonium ) {
8155 limit = limit / PLUTONIUM_CHARGES + ( limit % PLUTONIUM_CHARGES != 0 );
8156 }
8157
8158 qty = std::min( qty, limit );
8159
8160 casings_handle( [&u]( item & e ) {
8161 return u.i_add_or_drop( e );
8162 } );
8163
8164 if( is_magazine() ) {
8165 qty = std::min( qty, ammo->charges );
8166
8167 if( is_ammo_belt() && type->magazine->linkage ) {
8168 if( !u.use_charges_if_avail( *type->magazine->linkage, qty ) ) {
8169 debugmsg( "insufficient linkages available when reloading ammo belt" );
8170 }
8171 }
8172
8173 item to_reload = *ammo;
8174 to_reload.charges = qty;
8175 ammo->charges -= qty;
8176 bool merged = false;
8177 for( item *it : contents.all_items_top() ) {
8178 if( it->merge_charges( to_reload ) ) {
8179 merged = true;
8180 break;
8181 }
8182 }
8183 if( !merged ) {
8184 put_in( to_reload );
8185 }
8186 } else if( is_watertight_container() ) {
8187 if( !ammo->made_of( LIQUID ) ) {
8188 debugmsg( "Tried to reload liquid container with non-liquid." );
8189 return false;
8190 }
8191 if( container ) {
8192 container->on_contents_changed();
8193 }
8194 fill_with( *ammo, qty );
8195 } else if( !magazine_integral() ) {
8196 // if we already have a magazine loaded prompt to eject it
8197 if( magazine_current() ) {
8198 //~ %1$s: magazine name, %2$s: weapon name
8199 std::string prompt = string_format( pgettext( "magazine", "Eject %1$s from %2$s?" ),
8200 magazine_current()->tname(), tname() );
8201
8202 // eject magazine to player inventory and try to dispose of it from there
8203 item &mag = u.i_add( *magazine_current() );
8204 if( !u.dispose_item( item_location( u, &mag ), prompt ) ) {
8205 u.remove_item( mag ); // user canceled so delete the clone
8206 return false;
8207 }
8209 }
8210
8211 put_in( *ammo );
8212 loc.remove_item();
8213 return true;
8214
8215 } else {
8216 if( ammo->has_flag( flag_SPEEDLOADER ) ) {
8217 curammo = ammo->contents.front().type;
8218 qty = std::min( qty, ammo->ammo_remaining() );
8219 ammo->ammo_consume( qty, tripoint_zero );
8220 charges += qty;
8221 } else if( ammo->ammo_type() == ammo_plutonium ) {
8222 curammo = ammo->type;
8223 ammo->charges -= qty;
8224
8225 // any excess is wasted rather than overfilling the item
8226 charges += qty * PLUTONIUM_CHARGES;
8227 charges = std::min( charges, ammo_capacity() );
8228 } else {
8229 curammo = ammo->type;
8230 qty = std::min( qty, ammo->charges );
8231 ammo->charges -= qty;
8232 charges += qty;
8233 }
8234 }
8235
8236 if( ammo->charges == 0 && !ammo->has_flag( flag_SPEEDLOADER ) ) {
8237 if( container != nullptr ) {
8238 container->remove_item( container->contents.front() );
8239 u.inv.restack( u ); // emptied containers do not stack with non-empty ones
8240 } else {
8241 loc.remove_item();
8242 }
8243 }
8244 return true;
8245}
item & i_add(item it, bool should_stack=true)
Definition: character.cpp:2265
bool i_add_or_drop(item &it, int qty=1)
Sets invlet and adds to inventory if possible, drops otherwise, returns true if either succeeded.
Definition: character.cpp:2405
virtual bool dispose_item(item_location &&obj, const std::string &prompt=std::string())
Drop, wear, stash or otherwise try to dispose of an item consuming appropriate moves.
Definition: character.cpp:7263
void restack(player &p)
Definition: inventory.cpp:399
item * get_item()
Gets the selected item or nullptr.
void remove_item()
Removes the selected item from the game.
void fill_with(item &liquid, int amount=INFINITE_CHARGES)
Fill item with liquid up to its capacity.
Definition: item.cpp:8584
bool is_ammo_belt() const
Definition: item.cpp:6592
static constexpr int PLUTONIUM_CHARGES
static const ammotype ammo_plutonium("plutonium")
static const std::string flag_SPEEDLOADER("SPEEDLOADER")
@ prompt
Definition: pickup.h:30
static constexpr tripoint tripoint_zero
Definition: point.h:259

References item_contents::all_items_top(), ammo_capacity(), ammo_consume(), ammo_plutonium, ammo_remaining(), ammo_type(), casings_handle(), charges, contents, curammo, debugmsg, Character::dispose_item(), fill_with(), flag_SPEEDLOADER(), item_contents::front(), item_location::get_item(), get_remaining_capacity_for_liquid(), has_flag(), Character::i_add(), Character::i_add_or_drop(), Character::inv, is_ammo_belt(), is_ammo_container(), is_container(), is_magazine(), is_null(), is_reloadable_with(), is_watertight_container(), LIQUID, made_of(), itype::magazine, magazine_current(), magazine_integral(), on_contents_changed(), pgettext(), PLUTONIUM_CHARGES, pickup::prompt, put_in(), item_location::remove_item(), visitable< item >::remove_item(), visitable< T >::remove_item(), inventory::restack(), string_format(), tname(), tripoint_zero, type, typeId(), and Character::use_charges_if_avail().

Referenced by veh_interact::complete_vehicle(), npc::do_reload(), ranged::fire_gun(), and activity_handlers::reload_finish().

◆ remove_old_owner()

void item::remove_old_owner ( ) const
inline

Definition at line 2022 of file item.h.

2022 {
2024 }

References string_id< faction >::NULL_ID().

Referenced by talk_function::drop_stolen_item(), and validate_ownership().

◆ remove_owner()

void item::remove_owner ( ) const
inline

Definition at line 2029 of file item.h.

2029 {
2031 }

References string_id< faction >::NULL_ID().

Referenced by validate_ownership().

◆ repair_info()

void item::repair_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3173 of file item.cpp.

3175{
3177 return;
3178 }
3180 const std::vector<itype_id> &rep = sorted_lex( repaired_with() );
3181 if( !rep.empty() ) {
3182 info.emplace_back( "DESCRIPTION", string_format( _( "<bold>Repair</bold> using %s." ),
3183 enumerate_as_string( rep.begin(), rep.end(), []( const itype_id & e ) {
3184 return nname( e );
3186 if( reinforceable() ) {
3187 info.emplace_back( "DESCRIPTION", _( "* This item can be <good>reinforced</good>." ) );
3188 }
3189 } else {
3190 info.emplace_back( "DESCRIPTION", _( "* This item is <bad>not repairable</bad>." ) );
3191 }
3192}
bool reinforceable() const
Whether the item can be repaired beyond normal health.
Definition: item.cpp:6524
const std::set< itype_id > & repaired_with() const
If possible to repair this item what tools could potentially be used for this purpose?
Definition: item.cpp:6382

References _, DESCRIPTION_REPAIREDWITH, enumerate_as_string(), info(), insert_separation_line(), or_, reinforceable(), repaired_with(), sorted_lex(), string_format(), and iteminfo_query::test().

Referenced by info().

◆ repaired_with()

const std::set< itype_id > & item::repaired_with ( ) const

If possible to repair this item what tools could potentially be used for this purpose?

Definition at line 6382 of file item.cpp.

6383{
6384 static std::set<itype_id> no_repair;
6385 return has_flag( flag_NO_REPAIR ) ? no_repair : type->repair;
6386}
std::set< itype_id > repair
Damage scale compared to the old float damage value.
Definition: itype.h:979

References flag_NO_REPAIR(), has_flag(), itype::repair, and type.

Referenced by repair_info().

◆ reset_cable()

void item::reset_cable ( player p)

Helper to bring a cable back to its initial state.

Definition at line 9447 of file item.cpp.

9448{
9449 int max_charges = type->maximum_charges();
9450
9451 set_var( "state", "attach_first" );
9452 erase_var( "source_x" );
9453 erase_var( "source_y" );
9454 erase_var( "source_z" );
9455 active = false;
9456 charges = max_charges;
9457
9458 if( p != nullptr ) {
9459 p->add_msg_if_player( m_info, _( "You reel in the cable." ) );
9460 p->moves -= charges * 10;
9461 }
9462}

References _, active, player::add_msg_if_player(), charges, erase_var(), m_info, itype::maximum_charges(), Creature::moves, set_var(), and type.

Referenced by process_cable().

◆ rotten()

◆ serialize()

void item::serialize ( JsonOut json) const

Definition at line 2391 of file savegame_json.cpp.

2392{
2393 io::JsonObjectOutputArchive archive( json );
2394 const_cast<item *>( this )->io( archive );
2395 if( !contents.empty() ) {
2396 json.member( "contents", contents );
2397 }
2398}
void member(const std::string &name)
Definition: json.cpp:2235
Output archive matching the input archive JsonObjectInputArchive.
Definition: cata_io.h:351

References contents, item_contents::empty(), io(), and JsonOut::member().

Referenced by contain_monster().

◆ set_age()

void item::set_age ( const time_duration age)

Definition at line 10039 of file item.cpp.

10040{
10042}
void set_birthday(const time_point &bday)
Definition: item.cpp:10060

References age(), set_birthday(), and calendar::turn.

Referenced by burn(), iuse::firecracker_pack(), iuse::fish_trap(), iexamine::fvat_empty(), vehicle::operate_planter(), and map::process_fields_in_submap().

◆ set_birthday()

void item::set_birthday ( const time_point bday)

Definition at line 10060 of file item.cpp.

10061{
10062 this->bday = std::max( calendar::turn_zero, bday );
10063}

References bday, and calendar::turn_zero.

Referenced by editmap::edit_itm(), retroactively_fill_from_funnel(), set_age(), and debug_menu::wishitem().

◆ set_cached_tool_selections()

void item::set_cached_tool_selections ( const std::vector< comp_selection< tool_comp > > &  selections)

Definition at line 10141 of file item.cpp.

10142{
10143 assert( craft_data_ );
10144 craft_data_->cached_tool_selections = selections;
10145}

References craft_data_.

Referenced by craft_command::create_in_progress_craft().

◆ set_countdown()

void item::set_countdown ( int  num_turns)

Sets time until activation for an item that will self-activate in the future.

Definition at line 8619 of file item.cpp.

8620{
8621 if( num_turns < 0 ) {
8622 debugmsg( "Tried to set a negative countdown value %d.", num_turns );
8623 return;
8624 }
8625 if( !ammo_types().empty() ) {
8626 debugmsg( "Tried to set countdown on an item with ammo." );
8627 return;
8628 }
8629 charges = num_turns;
8630}

References ammo_types(), charges, and debugmsg.

Referenced by iuse_transform::use().

◆ set_damage()

item & item::set_damage ( int  qty)

Filter setting damage constrained by min_damage and max_damage.

Note
this method does not invoke the on_damage callback
Returns
same instance to allow method chaining

Definition at line 717 of file item.cpp.

718{
719 on_damage( qty - damage_, DT_TRUE );
720 damage_ = std::max( std::min( qty, max_damage() ), min_damage() );
721 return *this;
722}

References damage_, DT_TRUE, max_damage(), min_damage(), and on_damage().

Referenced by mdeath::broken(), editmap::edit_itm(), iuse::gun_repair(), Item_modifier::modify(), vehicle_part::properties_to_item(), repair_item_actor::repair(), game::save_cyborg(), vehicle::set_hp(), and map::spawn_an_item().

◆ set_favorite()

void item::set_favorite ( bool  favorite)

Definition at line 10113 of file item.cpp.

10114{
10115 is_favorite = favorite;
10116}

References is_favorite.

Referenced by advanced_inventory::display(), and inventory_column::set_stack_favorite().

◆ set_flag()

item & item::set_flag ( const std::string &  flag)

Idempotent filter setting an item specific flag.

Definition at line 5357 of file item.cpp.

5358{
5359 item_tags.insert( flag );
5360 return *this;
5361}
iterator insert(iterator, const value_type &value)
Definition: flat_set.h:151

References cata::flat_set< T, Compare, Data >::insert(), and item_tags.

Referenced by map::add_corpse(), ammo_set(), are_requirements_nearby(), iexamine::autodoc(), explosion_handler::ExplosionProcess::blast_tile(), butcher_cbm_item(), activity_handlers::butcher_finish(), butchery_quarter(), iuse::camera(), crafting::complete_disassemble(), recipe::create_byproducts(), Single_item_creator::create_single(), cycle_action(), game::dump_stats(), Character::eat(), heal_actor::finish_using(), basecamp::form_crafting_inventory(), inventory::form_from_map(), activity_handlers::repair_activity_hack::anonymous_namespace{activity_handlers.cpp}::get_fake_tool(), iuse_transform::info(), inherit_flags(), init_memory_card_with_random_stuff(), item(), Item_factory::migrate_item(), Item_modifier::modify(), explosion_handler::ExplosionProcess::move_entity(), iexamine::nanofab(), on_damage(), on_drop(), process_rot(), vehicle_part::properties_to_item(), iuse::radio_mod(), activity_handlers::reload_finish(), repair_item_actor::repair(), mattack::riotbot(), set_flag_recursive(), spell_effect::spawn_ethereal_item(), map::spawn_item(), starting_clothes(), starting_inv(), iuse::towel_common(), avatar_funcs::unload_item(), sew_advanced_actor::use(), unpack_actor::use(), iexamine::use_furn_fake_item(), and vehicle_part::vehicle_part().

◆ set_flag_recursive()

item & item::set_flag_recursive ( const std::string &  flag)

Idempotent filter recursively setting an item specific flag on this item and its components.

Definition at line 5369 of file item.cpp.

5370{
5371 set_flag( flag );
5372 for( item &comp : components ) {
5373 comp.set_flag_recursive( flag );
5374 }
5375 return *this;
5376}

References components, and set_flag().

◆ set_mtype()

void item::set_mtype ( const mtype m)

Sets the monster type associated with this item (corpse).

You must not pass a null pointer. TODO: change this to take a reference instead.

Definition at line 6677 of file item.cpp.

6678{
6679 // This is potentially dangerous, e.g. for corpse items, which *must* have a valid mtype pointer.
6680 if( m == nullptr ) {
6681 debugmsg( "setting item::corpse of %s to NULL", tname() );
6682 return;
6683 }
6684 corpse = m;
6685}

References corpse, debugmsg, and tname().

Referenced by iuse::blood_draw().

◆ set_next_failure_point()

void item::set_next_failure_point ( const player crafter)

Calculates and sets the next failure point for an in progress craft.

Causes a debugmsg if called on non-craft.

Parameters
crafterthe crafting player

Definition at line 904 of file crafting.cpp.

905{
906 if( !is_craft() ) {
907 debugmsg( "set_next_failure_point() called on non-craft '%s.' Aborting.", tname() );
908 return;
909 }
910
911 const int percent_left = 10000000 - item_counter;
912 const int failure_point_delta = crafter.crafting_success_roll( get_making() ) * percent_left;
913
914 craft_data_->next_failure_point = item_counter + failure_point_delta;
915}

References craft_data_, player::crafting_success_roll(), debugmsg, get_making(), is_craft(), item_counter, and tname().

Referenced by craft_command::create_in_progress_craft(), and handle_craft_failure().

◆ set_old_owner()

void item::set_old_owner ( const faction_id temp_owner)
inline

Definition at line 2019 of file item.h.

2019 {
2020 old_owner = temp_owner;
2021 }

Referenced by handle_pickup_ownership().

◆ set_owner() [1/2]

void item::set_owner ( const Character c)

Definition at line 1273 of file item.cpp.

1274{
1275 if( !c.get_faction() ) {
1276 debugmsg( "item::set_owner() Character %s has no valid faction", c.disp_name() );
1277 return;
1278 }
1279 owner = c.get_faction()->id;
1280}

References c, debugmsg, and owner.

◆ set_owner() [2/2]

◆ set_relative_rot()

void item::set_relative_rot ( double  val)

Set current item rot relative to shelf life (no-op if item does not spoil)

Definition at line 5564 of file item.cpp.

5565{
5566 if( goes_bad() ) {
5567 rot = get_shelf_life() * val;
5568 // calc_rot uses last_rot_check (when it's not turn_zero) instead of bday.
5569 // this makes sure the rotting starts from now, not from bday.
5570 // if this item is the result of smoking or milling don't do this, we want to start from bday.
5573 }
5574 }
5575}
static const std::string flag_PROCESSING_RESULT("PROCESSING_RESULT")

References flag_PROCESSING_RESULT(), get_shelf_life(), goes_bad(), has_flag(), last_rot_check, and calendar::turn.

Referenced by complete_craft(), fill_with(), item(), and iexamine::keg().

◆ set_rot()

void item::set_rot ( time_duration  val)

Definition at line 5577 of file item.cpp.

5578{
5579 rot = val;
5580}

◆ set_side()

bool item::set_side ( side  s)

Change the side on which the item is worn.

Returns false if the item is not sided

Definition at line 818 of file item.cpp.

819{
820 if( !is_sided() ) {
821 return false;
822 }
823
824 if( s == side::BOTH ) {
825 erase_var( "lateral" );
826 } else {
827 set_var( "lateral", static_cast<int>( s ) );
828 }
829
830 return true;
831}

References BOTH, erase_var(), is_sided(), and set_var().

Referenced by on_takeoff(), on_wear(), and swap_side().

◆ set_snippet()

void item::set_snippet ( const snippet_id id)

Set the snippet text (description) of this specific item, using the snippet library.

See also
snippet_library.

Definition at line 8695 of file item.cpp.

8696{
8697 if( is_null() ) {
8698 return;
8699 }
8700 if( !id.is_valid() ) {
8701 debugmsg( "there's no snippet with id %s", id.str() );
8702 return;
8703 }
8704 snip_id = id;
8705}

References debugmsg, base_camps::id, is_null(), and snip_id.

Referenced by profession::items().

◆ set_tools_to_continue()

void item::set_tools_to_continue ( bool  value)

Definition at line 10129 of file item.cpp.

10130{
10131 assert( craft_data_ );
10132 craft_data_->tools_to_continue = value;
10133}

References craft_data_.

Referenced by craft_command::create_in_progress_craft().

◆ set_var() [1/6]

void item::set_var ( const std::string &  name,
const std::string &  value 
)

Definition at line 1059 of file item.cpp.

1060{
1061 item_vars[name] = value;
1062}

References item_vars, and om_direction::name().

◆ set_var() [2/6]

void item::set_var ( const std::string &  name,
const tripoint value 
)

Definition at line 1042 of file item.cpp.

1043{
1044 item_vars[name] = string_format( "%d,%d,%d", value.x, value.y, value.z );
1045}
int y
Definition: point.h:137
int x
Definition: point.h:136

References item_vars, om_direction::name(), string_format(), tripoint::x, tripoint::y, and tripoint::z.

◆ set_var() [3/6]

void item::set_var ( const std::string &  name,
double  value 
)

Definition at line 1028 of file item.cpp.

1029{
1030 item_vars[name] = string_format( "%f", value );
1031}

References item_vars, om_direction::name(), and string_format().

◆ set_var() [4/6]

◆ set_var() [5/6]

void item::set_var ( const std::string &  name,
long long  value 
)

Definition at line 1011 of file item.cpp.

1012{
1013 std::ostringstream tmpstream;
1014 tmpstream.imbue( std::locale::classic() );
1015 tmpstream << value;
1016 item_vars[name] = tmpstream.str();
1017}

References item_vars, and om_direction::name().

◆ set_var() [6/6]

void item::set_var ( const std::string &  name,
long  value 
)

Definition at line 1020 of file item.cpp.

1021{
1022 std::ostringstream tmpstream;
1023 tmpstream.imbue( std::locale::classic() );
1024 tmpstream << value;
1025 item_vars[name] = tmpstream.str();
1026}

References item_vars, and om_direction::name().

◆ sight_dispersion()

int item::sight_dispersion ( ) const

Get lowest dispersion of either integral or any attached sights.

Definition at line 7273 of file item.cpp.

7274{
7275 if( !is_gun() ) {
7276 return 0;
7277 }
7278
7279 int res = has_flag( flag_DISABLE_SIGHTS ) ? 90 : type->gun->sight_dispersion;
7280
7281 for( const item *e : gunmods() ) {
7282 const islot_gunmod &mod = *e->type->gunmod;
7283 if( mod.sight_dispersion < 0 || mod.aim_speed < 0 ) {
7284 continue; // skip gunmods which don't provide a sight
7285 }
7286 res = std::min( res, mod.sight_dispersion );
7287 }
7288
7289 return res;
7290}

References flag_DISABLE_SIGHTS(), itype::gun, gunmods(), has_flag(), is_gun(), and type.

Referenced by ranged::get_aim_types(), target_ui::panel_recoil(), print_aim(), and target_ui::run().

◆ simulate_burn()

float item::simulate_burn ( fire_data frd) const

Calculate all burning calculations, but don't actually apply them to item.

DO apply them to fire_data argument, though.

Returns
Amount of "burn" that would be applied to the item.

Definition at line 8247 of file item.cpp.

8248{
8249 const std::vector<material_id> &mats = made_of();
8250 float smoke_added = 0.0f;
8251 float time_added = 0.0f;
8252 float burn_added = 0.0f;
8253 const units::volume vol = base_volume();
8254 const int effective_intensity = frd.contained ? 3 : frd.fire_intensity;
8255 for( const material_id &m : mats ) {
8256 const mat_burn_data &bd = m.obj().burn_data( effective_intensity );
8257 if( bd.immune ) {
8258 // Made to protect from fire
8259 return 0.0f;
8260 }
8261
8262 // If fire is contained, burn rate is independent of volume
8263 if( frd.contained || bd.volume_per_turn == 0_ml ) {
8264 time_added += bd.fuel;
8265 smoke_added += bd.smoke;
8266 burn_added += bd.burn;
8267 } else {
8268 double volume_burn_rate = to_liter( bd.volume_per_turn ) / to_liter( vol );
8269 time_added += bd.fuel * volume_burn_rate;
8270 smoke_added += bd.smoke * volume_burn_rate;
8271 burn_added += bd.burn * volume_burn_rate;
8272 }
8273 }
8274
8275 // Liquids that don't burn well smother fire well instead
8276 if( made_of( LIQUID ) && time_added < 200 ) {
8277 time_added -= rng( 400.0 * to_liter( vol ), 1200.0 * to_liter( vol ) );
8278 } else if( mats.size() > 1 ) {
8279 // Average the materials
8280 time_added /= mats.size();
8281 smoke_added /= mats.size();
8282 burn_added /= mats.size();
8283 } else if( mats.empty() ) {
8284 // Non-liquid items with no specified materials will burn at moderate speed
8285 burn_added = 1;
8286 }
8287
8288 if( count_by_charges() ) {
8289 int stack_burnt = rng( type->stack_size / 2, type->stack_size );
8290 time_added *= stack_burnt;
8291 smoke_added *= stack_burnt;
8292 burn_added *= stack_burnt;
8293 }
8294
8295 frd.fuel_produced += time_added;
8296 frd.smoke_produced += smoke_added;
8297 return burn_added;
8298}
constexpr double to_liter(const volume &v)
Definition: units_volume.h:43
int fire_intensity
Current intensity of the fire.
Definition: fire.h:25
float fuel_produced
Fuel contributed by each burning item this turn is summed here.
Definition: fire.h:29
float smoke_produced
Smoke produced by each burning item this turn is summed here.
Definition: fire.h:27
bool contained
The fire is contained and burned for fuel intentionally.
Definition: fire.h:31
float smoke
Smoke produced per tick when this material burns.
Definition: fire.h:54
float burn
Volume of material destroyed per tick when this material burns.
Definition: fire.h:56

References base_volume(), mat_burn_data::burn, fire_data::contained, count_by_charges(), fire_data::fire_intensity, mat_burn_data::fuel, fire_data::fuel_produced, mat_burn_data::immune, LIQUID, made_of(), rng(), mat_burn_data::smoke, fire_data::smoke_produced, itype::stack_size, units::to_liter(), type, and mat_burn_data::volume_per_turn.

Referenced by burn(), and try_fuel_fire().

◆ spill_contents() [1/2]

bool item::spill_contents ( Character c)

Unloads the item's contents.

Parameters
cCharacter who receives the contents. If c is the player, liquids will be handled, otherwise they will be spilled.
Returns
If the item is now empty.

Definition at line 7084 of file item.cpp.

7085{
7086 if( !is_container() || is_container_empty() ) {
7087 return true;
7088 }
7089
7090 if( c.is_npc() ) {
7091 return spill_contents( c.pos() );
7092 }
7093
7096
7097 return true;
7098}
void handle_liquid_or_spill(Character &guy)
bool spill_contents(Character &c)
Unloads the item's contents.
Definition: item.cpp:7084

References c, contents, item_contents::handle_liquid_or_spill(), is_container(), is_container_empty(), on_contents_changed(), and spill_contents().

Referenced by drop_or_embed_projectile(), pickup::handle_spillable_contents(), Character::i_rem_keep_contents(), pick_one_up(), smash(), and spill_contents().

◆ spill_contents() [2/2]

bool item::spill_contents ( const tripoint pos)

Unloads the item's contents.

Parameters
posPosition to dump the contents on.
Returns
If the item is now empty.

Definition at line 7100 of file item.cpp.

7101{
7102 if( !is_container() || is_container_empty() ) {
7103 return true;
7104 }
7105
7106 for( item *it : contents.all_items_top() ) {
7107 get_map().add_item_or_charges( pos, *it );
7108 }
7109
7111 return true;
7112}

References map::add_item_or_charges(), item_contents::all_items_top(), item_contents::clear_items(), contents, get_map(), is_container(), and is_container_empty().

◆ split()

item item::split ( int  qty)

Splits a count-by-charges item always leaving source item with minimum of 1 charge.

Parameters
qtynumber of required charges to split from source
Returns
new instance containing exactly qty charges or null item if splitting failed

Definition at line 724 of file item.cpp.

725{
726 if( !count_by_charges() || qty <= 0 || qty >= charges ) {
727 return item();
728 }
729 item res = *this;
730 res.charges = qty;
731 charges -= qty;
732 return res;
733}

References charges, count_by_charges(), and item().

Referenced by iexamine::gaspump(), Character::item_reload_cost(), item_location::impl::item_on_map::obtain(), item_location::impl::item_on_person::obtain(), item_location::impl::item_on_vehicle::obtain(), item_location::impl::item_in_container::obtain(), item_location::impl::item_on_map::obtain_cost(), item_location::impl::item_on_person::obtain_cost(), item_location::impl::item_on_vehicle::obtain_cost(), and bandolier_actor::reload().

◆ spoilage_sort_order()

int item::spoilage_sort_order ( ) const

Get time left to rot, ignoring fridge.

Returns time to rot if item is able to, max int - N otherwise, where N is 3 for food, 2 for medication, 1 for other comestibles, 0 otherwise.

Definition at line 5582 of file item.cpp.

5583{
5584 const item *subject;
5585 constexpr int bottom = std::numeric_limits<int>::max();
5586
5587 if( type->container && !contents.empty() ) {
5588 if( type->container->preserves ) {
5589 return bottom - 3;
5590 }
5591 subject = &contents.front();
5592 } else {
5593 subject = this;
5594 }
5595
5596 if( subject->goes_bad() ) {
5597 return to_turns<int>( subject->get_shelf_life() - subject->rot );
5598 }
5599
5600 if( subject->get_comestible() ) {
5601 if( subject->get_category().get_id() == itemcat_food ) {
5602 return bottom - 3;
5603 } else if( subject->get_category().get_id() == itemcat_drugs ) {
5604 return bottom - 2;
5605 } else {
5606 return bottom - 1;
5607 }
5608 }
5609 return bottom;
5610}
static const item_category_id itemcat_drugs("drugs")
static const item_category_id itemcat_food("food")

References itype::container, contents, item_contents::empty(), item_contents::front(), get_category(), get_comestible(), item_category::get_id(), get_shelf_life(), goes_bad(), itemcat_drugs, itemcat_food, rot, and type.

Referenced by find_auto_consume().

◆ stab_resist()

int item::stab_resist ( bool  to_self = false) const

Definition at line 6117 of file item.cpp.

6118{
6119 // Better than hardcoding it in multiple places
6120 return static_cast<int>( 0.8f * cut_resist( to_self ) );
6121}

References cut_resist().

Referenced by damage_resist().

◆ stacks_with()

bool item::stacks_with ( const item rhs,
bool  check_components = false,
bool  skip_type_check = false 
) const

Definition at line 892 of file item.cpp.

893{
894 if( !skip_type_check && type != rhs.type ) {
895 return false;
896 }
897 if( is_relic() && rhs.is_relic() && !( *relic_data == *rhs.relic_data ) ) {
898 return false;
899 }
900 if( charges != 0 && rhs.charges != 0 && is_money() ) {
901 // Dealing with nonempty cash cards
902 return true;
903 }
904 // This function is also used to test whether items counted by charges should be merged, for that
905 // check the, the charges must be ignored. In all other cases (tools/guns), the charges are important.
906 if( !count_by_charges() && charges != rhs.charges ) {
907 return false;
908 }
909 if( is_favorite != rhs.is_favorite ) {
910 return false;
911 }
912 if( damage_ != rhs.damage_ ) {
913 return false;
914 }
915 if( burnt != rhs.burnt ) {
916 return false;
917 }
918 if( active != rhs.active ) {
919 return false;
920 }
921 if( item_tags != rhs.item_tags ) {
922 return false;
923 }
924 if( faults != rhs.faults ) {
925 return false;
926 }
927 if( techniques != rhs.techniques ) {
928 return false;
929 }
930 if( item_vars != rhs.item_vars ) {
931 return false;
932 }
933 if( goes_bad() && rhs.goes_bad() ) {
934 // Stack items that fall into the same "bucket" of freshness.
935 // Distant buckets are larger than near ones.
936 std::pair<int, clipped_unit> my_clipped_time_to_rot =
938 std::pair<int, clipped_unit> other_clipped_time_to_rot =
939 clipped_time( rhs.get_shelf_life() - rhs.rot );
940 if( my_clipped_time_to_rot != other_clipped_time_to_rot ) {
941 return false;
942 }
943 if( rotten() != rhs.rotten() ) {
944 // just to be safe that rotten and unrotten food is *never* stacked.
945 return false;
946 }
947 }
948 if( ( corpse == nullptr && rhs.corpse != nullptr ) ||
949 ( corpse != nullptr && rhs.corpse == nullptr ) ) {
950 return false;
951 }
952 if( corpse != nullptr && rhs.corpse != nullptr && corpse->id != rhs.corpse->id ) {
953 return false;
954 }
955 if( craft_data_ || rhs.craft_data_ ) {
956 // In-progress crafts are always distinct items. Easier to handle for the player,
957 // and there shouldn't be that many items of this type around anyway.
958 return false;
959 }
960 if( check_components || is_comestible() || is_craft() ) {
961 //Only check if at least one item isn't using the default recipe or is comestible
962 if( !components.empty() || !rhs.components.empty() ) {
964 return false;
965 }
966 }
967 }
969 return false;
970 }
971
972 if( ammo_current() != rhs.ammo_current() ) {
973 return false;
974 }
975
976 return contents.stacks_with( rhs.contents );
977}
std::pair< int, clipped_unit > clipped_time(const time_duration &d)
Returns a value representing the passed in duration truncated to an appropriate unit along with the u...
Definition: calendar.cpp:284
bool stacks_with(const item_contents &rhs) const
std::vector< item_comp > get_uncraft_components() const
Returns a list of components used to craft this item or the default components if it wasn't player-cr...
Definition: item.cpp:10086

References active, ammo_current(), burnt, charges, clipped_time(), components, contents, corpse, count_by_charges(), craft_data_, damage_, faults, get_shelf_life(), get_uncraft_components(), goes_bad(), mtype::id, is_comestible(), is_craft(), is_favorite, is_money(), is_relic(), item_tags, item_vars, item_contents::num_item_stacks(), relic_data, rot, rotten(), item_contents::stacks_with(), techniques, and type.

Referenced by display_stacked_with(), merge_charges(), inventory::restack(), inventory_column::set_stack_favorite(), and npc_trading::transfer_items().

◆ swap_side()

bool item::swap_side ( )

Swap the side on which the item is worn.

Returns false if the item is not sided

Definition at line 833 of file item.cpp.

834{
835 return set_side( opposite_side( get_side() ) );
836}
side opposite_side(side s)
Returns the opposite side.
Definition: bodypart.cpp:30

References get_side(), opposite_side(), and set_side().

Referenced by Character::change_side().

◆ symbol()

const std::string & item::symbol ( ) const

Definition at line 4142 of file item.cpp.

4143{
4144 return type->sym;
4145}
std::string sym
Definition: itype.h:973

References itype::sym, and type.

Referenced by map::draw_maptile(), map_memory::load_legacy(), mm_elem::operator==(), pickup::pick_up(), mm_submap::serialize(), and debug_menu::wishitem().

◆ tname()

std::string item::tname ( unsigned int  quantity = 1,
bool  with_prefix = true,
unsigned int  truncate = 0 
) const

Return the (translated) item name.

Parameters
quantityused for translation to the proper plural form of the name, e.g. returns "rock" for quantity 1 and "rocks" for quantity > 0.
with_prefixdetermines whether to include more item properties, such as the extent of damage and burning (was created to sort by name without prefix in additional inventory)

Definition at line 4574 of file item.cpp.

4575{
4576 int dirt_level = get_var( "dirt", 0 ) / 2000;
4577 std::string dirt_symbol;
4578 // TODO: MATERIALS put this in json
4579
4580 // these symbols are unicode square characeters of different heights, representing a rough
4581 // estimation of fouling in a gun. This appears instead of "faulty"
4582 // since most guns will have some level of fouling in them, and usually it is not a big deal.
4583 switch( dirt_level ) {
4584 case 0:
4585 dirt_symbol = "";
4586 break;
4587 case 1:
4588 dirt_symbol = "<color_white>\u2581</color>";
4589 break;
4590 case 2:
4591 dirt_symbol = "<color_light_gray>\u2583</color>";
4592 break;
4593 case 3:
4594 dirt_symbol = "<color_light_gray>\u2585</color>";
4595 break;
4596 case 4:
4597 dirt_symbol = "<color_dark_gray>\u2587</color>";
4598 break;
4599 case 5:
4600 dirt_symbol = "<color_brown>\u2588</color>";
4601 break;
4602 default:
4603 dirt_symbol = "";
4604 }
4605 std::string damtext;
4606
4607 // for portions of string that have <color_ etc in them, this aims to truncate the whole string correctly
4608 unsigned int truncate_override = 0;
4609
4610 if( ( damage() != 0 || ( get_option<bool>( "ITEM_HEALTH_BAR" ) && is_armor() ) ) && !is_null() &&
4611 with_prefix ) {
4612 damtext = durability_indicator();
4613 if( get_option<bool>( "ITEM_HEALTH_BAR" ) ) {
4614 // get the utf8 width of the tags
4615 truncate_override = utf8_width( damtext, false ) - utf8_width( damtext, true );
4616 }
4617 }
4618 if( !faults.empty() ) {
4619 bool silent = true;
4620 for( const auto &fault : faults ) {
4621 if( !fault->has_flag( flag_SILENT ) ) {
4622 silent = false;
4623 break;
4624 }
4625 }
4626 if( silent ) {
4627 damtext.insert( 0, dirt_symbol );
4628 } else {
4629 damtext.insert( 0, _( "faulty " ) + dirt_symbol );
4630 }
4631 }
4632
4633 std::string vehtext;
4634 if( is_engine() && engine_displacement() > 0 ) {
4635 vehtext = string_format( pgettext( "vehicle adjective", "%2.1fL " ),
4636 engine_displacement() / 100.0f );
4637
4638 } else if( is_wheel() && type->wheel->diameter > 0 ) {
4639 vehtext = string_format( pgettext( "vehicle adjective", "%d\" " ), type->wheel->diameter );
4640 }
4641
4642 std::string burntext;
4643 if( with_prefix && !made_of( LIQUID ) ) {
4644 if( volume() >= 1_liter && burnt * 125_ml >= volume() ) {
4645 burntext = pgettext( "burnt adjective", "badly burnt " );
4646 } else if( burnt > 0 ) {
4647 burntext = pgettext( "burnt adjective", "burnt " );
4648 }
4649 }
4650
4651 std::string maintext;
4652 if( is_corpse() || typeId() == itype_blood || item_vars.find( "name" ) != item_vars.end() ) {
4653 maintext = type_name( quantity );
4654 } else if( is_gun() || is_tool() || is_magazine() ) {
4655 int amt = 0;
4656 maintext = label( quantity );
4657 for( const item *mod : is_gun() ? gunmods() : toolmods() ) {
4658 if( !type->gun || !type->gun->built_in_mods.count( mod->typeId() ) ) {
4659 amt++;
4660 }
4661 }
4662 if( amt ) {
4663 maintext += string_format( "+%d", amt );
4664 }
4665 } else if( is_armor() && has_clothing_mod() ) {
4666 maintext = label( quantity ) + "+1";
4667 } else if( is_craft() ) {
4668 maintext = string_format( _( "in progress %s" ), craft_data_->making->result_name() );
4669 if( charges > 1 ) {
4670 maintext += string_format( " (%d)", charges );
4671 }
4672 const int percent_progress = item_counter / 100000;
4673 maintext += string_format( " (%d%%)", percent_progress );
4674 } else if( contents.num_item_stacks() == 1 ) {
4675 const item &contents_item = contents.front();
4676 const unsigned contents_count =
4677 ( ( contents_item.made_of( LIQUID ) || contents_item.is_food() ) &&
4678 contents_item.charges > 1 )
4679 ? contents_item.charges
4680 : quantity;
4681 maintext = string_format( pgettext( "item name", "%2$s (%1$s)" ), label( quantity ),
4682 contents_item.tname( contents_count, with_prefix ) );
4683 } else if( !contents.empty() ) {
4684 maintext = string_format( vpgettext( "item name",
4685 //~ %1$s: item name, %2$zd: content size
4686 "%1$s with %2$zd item",
4687 "%1$s with %2$zd items", contents.num_item_stacks() ),
4688 label( quantity ), contents.num_item_stacks() );
4689 } else {
4690 maintext = label( quantity );
4691 }
4692
4693 avatar &you = get_avatar();
4694 std::string tagtext;
4695 if( is_food() ) {
4697 tagtext += _( " (poisonous)" );
4698 } else if( has_flag( flag_HIDDEN_HALLU ) && you.get_skill_level( skill_survival ) >= 5 ) {
4699 tagtext += _( " (hallucinogenic)" );
4700 }
4701 }
4702 if( is_book() ) {
4703 if( !you.has_identified( typeId() ) ) {
4704 tagtext += _( " (unread)" );
4705 }
4706 }
4707 if( has_var( "bionics_scanned_by" ) && has_flag( flag_CBM_SCANNED ) ) {
4708 tagtext += _( " (bionic detected)" );
4709 }
4710 if( has_flag( flag_ETHEREAL_ITEM ) ) {
4711 tagtext += string_format( _( " (%s turns)" ), get_var( "ethereal" ) );
4712 } else if( goes_bad() || is_food() ) {
4713 if( has_own_flag( "DIRTY" ) ) {
4714 tagtext += _( " (dirty)" );
4715 } else if( rotten() ) {
4716 tagtext += _( " (rotten)" );
4717 } else if( is_going_bad() ) {
4718 tagtext += _( " (old)" );
4719 } else if( is_fresh() ) {
4720 tagtext += _( " (fresh)" );
4721 }
4722 if( has_flag( flag_COLD ) ) {
4723 tagtext += _( " (cold)" );
4724 } else if( has_flag( flag_VERY_COLD ) ) {
4725 tagtext += _( " (very cold)" );
4726 }
4727 }
4728
4729 const sizing sizing_level = get_sizing( you, get_encumber( you ) != 0 );
4730
4731 if( sizing_level == sizing::human_sized_small_char ) {
4732 tagtext += _( " (too big)" );
4733 } else if( sizing_level == sizing::big_sized_small_char ) {
4734 tagtext += _( " (huge!)" );
4735 } else if( sizing_level == sizing::human_sized_big_char ||
4736 sizing_level == sizing::small_sized_human_char ) {
4737 tagtext += _( " (too small)" );
4738 } else if( sizing_level == sizing::small_sized_big_char ) {
4739 tagtext += _( " (tiny!)" );
4740 } else if( !has_flag( flag_FIT ) && has_flag( flag_VARSIZE ) ) {
4741 tagtext += _( " (poor fit)" );
4742 }
4743
4744 if( is_filthy() ) {
4745 tagtext += _( " (filthy)" );
4746 }
4748 tagtext += _( " (sterile)" );
4749 }
4750
4751 if( is_tool() && has_flag( flag_USE_UPS ) && !has_flag( flag_NAT_UPS ) ) {
4752 tagtext += _( " (UPS)" );
4753 }
4754 if( is_tool() && has_flag( flag_HEATS_FOOD ) ) {
4755 tagtext += _( " (heats)" );
4756 }
4757
4758 if( has_var( "NANOFAB_ITEM_ID" ) ) {
4759 tagtext += string_format( " (%s)", nname( itype_id( get_var( "NANOFAB_ITEM_ID" ) ) ) );
4760 }
4761
4762 if( has_flag( flag_RADIO_MOD ) ) {
4763 tagtext += _( " (radio:" );
4764 if( has_flag( flag_RADIOSIGNAL_1 ) ) {
4765 tagtext += pgettext( "The radio mod is associated with the [R]ed button.", "R)" );
4766 } else if( has_flag( flag_RADIOSIGNAL_2 ) ) {
4767 tagtext += pgettext( "The radio mod is associated with the [B]lue button.", "B)" );
4768 } else if( has_flag( flag_RADIOSIGNAL_3 ) ) {
4769 tagtext += pgettext( "The radio mod is associated with the [G]reen button.", "G)" );
4770 } else {
4771 debugmsg( "Why is the radio neither red, blue, nor green?" );
4772 tagtext += "?)";
4773 }
4774 }
4775
4776 if( has_flag( flag_WET ) ) {
4777 tagtext += _( " (wet)" );
4778 }
4779 if( already_used_by_player( you ) ) {
4780 tagtext += _( " (used)" );
4781 }
4783 tagtext += _( " (lit)" );
4784 } else if( has_flag( flag_IS_UPS ) && get_var( "cable" ) == "plugged_in" ) {
4785 tagtext += _( " (plugged in)" );
4786 } else if( active && !is_food() && !is_corpse() &&
4787 !string_ends_with( typeId().str(), "_on" ) ) {
4788 // Usually the items whose ids end in "_on" have the "active" or "on" string already contained
4789 // in their name, also food is active while it rots.
4790 tagtext += _( " (active)" );
4791 }
4792
4793 if( is_favorite ) {
4794 tagtext += _( " *" ); // Display asterisk for favorite items
4795 }
4796
4797 std::string modtext;
4799 modtext += _( "sawn-off " );
4800 }
4802 modtext += _( "pistol " );
4803 }
4804 if( has_flag( flag_DIAMOND ) ) {
4805 modtext += std::string( pgettext( "Adjective, as in diamond katana", "diamond" ) ) + " ";
4806 }
4807
4808 //~ This is a string to construct the item name as it is displayed. This format string has been added for maximum flexibility. The strings are: %1$s: Damage text (e.g. "bruised"). %2$s: burn adjectives (e.g. "burnt"). %3$s: tool modifier text (e.g. "atomic"). %4$s: vehicle part text (e.g. "3.8-Liter"). $5$s: main item text (e.g. "apple"). %6s: tags (e.g. "(wet) (poor fit)").
4809 std::string ret = string_format( _( "%1$s%2$s%3$s%4$s%5$s%6$s" ), damtext, burntext, modtext,
4810 vehtext, maintext, tagtext );
4811
4812 if( truncate != 0 ) {
4813 ret = utf8_truncate( ret, truncate + truncate_override );
4814 }
4815
4816 if( item_vars.find( "item_note" ) != item_vars.end() ) {
4817 //~ %s is an item name. This style is used to denote items with notes.
4818 return string_format( _( "*%s*" ), ret );
4819 } else {
4820 return ret;
4821 }
4822}
int utf8_width(const char *s, const bool ignore_tags)
std::string utf8_truncate(const std::string &s, size_t length)
bool has_flag(const std::string &flag) const
Definition: fault.h:61
bool is_wheel() const
Definition: item.cpp:6780
bool is_going_bad() const
an item is about to become rotten when shelf life has nearly elapsed
Definition: item.h:844
std::string durability_indicator(bool include_intact=false) const
Provides a prefix for the durability state of the item.
Definition: item.cpp:6341
std::string label(unsigned int quantity=0) const
Returns label from "item_label" itemvar and quantity.
Definition: item.cpp:9981
bool is_fresh() const
an item is fresh if it is capable of rotting but still has a long shelf life remaining
Definition: item.h:839
bool has_clothing_mod() const
Definition: item.cpp:10162
int engine_displacement() const
for combustion engines the displacement (cc)
Definition: item.cpp:4137
bool already_used_by_player(const player &p) const
Check whether the item has been marked (by calling mark_as_used_by_player) as used by this specific p...
Definition: item.cpp:8869
static const itype_id itype_blood("blood")
static const std::string flag_SILENT("SILENT")
static const std::string flag_HEATS_FOOD("HEATS_FOOD")
static const itype_id itype_stock_small("stock_small")
static const std::string flag_NAT_UPS("NAT_UPS")
static const itype_id itype_barrel_small("barrel_small")
static const std::string flag_CBM_SCANNED("CBM_SCANNED")
bool string_ends_with(const std::string &s1, const std::string &s2)
Returns true if s1 ends with s2.
Struct used for storing labels (easier to json opposed to a std::map<point, std::string>)
Definition: vehicle.h:579
const char * vpgettext(const char *const context, const char *const msgid, const char *const msgid_plural, const size_t n)
@ silent
Definition: weather_type.h:56

References _, active, already_used_by_player(), big_sized_small_char, burnt, charges, contents, craft_data_, damage(), debugmsg, durability_indicator(), item_contents::empty(), engine_displacement(), fault_bionic_nonsterile, faults, flag_CBM_SCANNED(), flag_COLD(), flag_DIAMOND(), flag_ETHEREAL_ITEM(), flag_FIT(), flag_HEATS_FOOD(), flag_HIDDEN_HALLU(), flag_HIDDEN_POISON(), flag_IS_UPS(), flag_LITCIG(), flag_NAT_UPS(), flag_RADIO_MOD(), flag_RADIOSIGNAL_1(), flag_RADIOSIGNAL_2(), flag_RADIOSIGNAL_3(), flag_SILENT(), flag_USE_UPS(), flag_VARSIZE(), flag_VERY_COLD(), flag_WATER_EXTINGUISH(), flag_WET(), item_contents::front(), get_avatar(), get_encumber(), get_sizing(), Character::get_skill_level(), get_var(), goes_bad(), itype::gun, gunmod_find(), gunmods(), has_clothing_mod(), has_fault(), fault::has_flag(), has_flag(), avatar::has_identified(), has_own_flag(), has_var(), human_sized_big_char, human_sized_small_char, is_armor(), is_bionic(), is_book(), is_corpse(), is_craft(), is_engine(), is_favorite, is_filthy(), is_food(), is_fresh(), is_going_bad(), is_gun(), is_magazine(), is_null(), is_tool(), is_wheel(), item_counter, item_vars, itype_barrel_small, itype_blood, itype_id, itype_stock_small, label(), LIQUID, made_of(), nname(), item_contents::num_item_stacks(), pgettext(), cata::hash64_detail::ret, rotten(), silent, skill_survival, small_sized_big_char, small_sized_human_char, string_ends_with(), string_format(), tname(), toolmods(), type, type_name(), typeId(), utf8_truncate(), utf8_width(), volume(), vpgettext(), and itype::wheel.

Referenced by Character::absorb_hit(), advanced_inventory::action_examine(), monexamine::add_armor(), game::add_artifact_dreams(), add_disassemblables(), MapgenRemovePartHandler::add_item_or_charges(), advanced_inventory_pane::add_items_from_area(), auto_pickup::player_settings::add_rule(), add_salvagables(), npc::alt_attack(), ammo_consume(), apply_lock_picking_tool(), apply_prying_tool(), Character::armor_absorb(), iuse::artifact(), inventory::assign_empty_invlet(), mattack::bio_op_disarm(), talk_function::bionic_remove(), Character::block_hit(), Character::block_ranged_hit(), iuse::blood_draw(), iuse::burrow(), activity_handlers::butcher_finish(), camp_car_description(), use_function::can_call(), npc::can_read(), repair_item_actor::can_repair_target(), Character::can_unwield(), Character::can_use(), Character::can_wear(), Character::can_wield(), iuse::capture_monster_act(), iuse::capture_monster_veh(), Character::change_side(), charges_per_volume(), iuse::chew(), iuse::coin_flip(), colorized_item_name(), game_menus::inv::compare(), crafting::complete_disassemble(), npc::confident_gun_mode_range(), Character::consume(), Character::consume_item(), iuse::contacts(), game_menus::inv::container_for(), iuse::craft(), auto_pickup::rule_list::create_rule(), iuse::crowbar(), salvage_actor::cut_up(), damage_item(), deactivate(), item_location::impl::item_in_container::describe(), iexamine::dimensional_portal(), iuse::directional_hologram(), display_money(), display_name(), iuse::dive_tank(), npc::do_reload(), draw_bionics_titlebar(), npc::drop_items(), drop_on_map(), drop_or_embed_projectile(), avatar_action::eat(), Character::eat(), iuse::ehandcuffs(), iuse::einktabletpc(), explosion_handler::emp_blast(), npc::execute_action(), Character::extended_description(), iuse::eyedrops(), Character::feed_furnace_with(), fetch_activity(), activity_handlers::fill_liquid_do_turn(), fill_with(), final_info(), npc::find_item(), heal_actor::finish_using(), ranged::fire_gun(), avatar_action::fire_wielded_weapon(), iuse::firecracker_act(), iexamine::fireplace(), iuse::fishing_rod(), iuse::flumed(), iuse::flusleep(), character_funcs::fmt_wielded_weapon(), Character::fuel_bionic_with(), iexamine::fvat_empty(), iexamine::fvat_full(), activity_handlers::game_do_turn(), iuse::gasmask(), generic_multi_activity_do(), avatar::get_book_reader(), get_continue_reqs(), get_encumber_when_containing(), get_making(), get_next_failure_point(), get_owner_name(), get_property_int64_t(), get_remaining_capacity_for_liquid(), vehicle::get_targeting_npc(), talk_function::give_equipment(), monexamine::give_items_to(), iuse::granade_act(), iuse::gun_repair(), avatar_funcs::gunmod_add(), activity_handlers::gunmod_add_finish(), avatar_funcs::gunmod_remove(), ranged::gunmode_checks_common(), ranged::gunmode_checks_weapon(), iuse::hand_crank(), repair_item_actor::handle_components(), handle_craft_failure(), ranged::handle_gun_damage(), liquid_handler::handle_liquid(), Character::handle_melee_wear(), handle_problematic_pickup(), Character::has_enough_charges(), auto_pickup::player_settings::has_rule(), npc::heal_self(), Character::i_add_to_container(), Character::i_rem(), ideal_ranged_dps(), iuse_transform::info(), info(), Character::invoke_item(), avatar::invoke_item(), advanced_inventory_pane::is_filtered(), Character::item_reload_cost(), npc::item_whitelisted(), iuse::jackhammer(), iexamine::keg(), game::list_items(), aim_activity_actor::load_RAS_weapon(), iuse::magic_8_ball(), marloss_common(), iuse::marloss_seed(), character_martial_arts::martialart_use_message(), iuse::meditate(), iuse::melatonin_tablet(), Character::melee_special_effects(), activity_handlers::mend_item_finish(), iuse::mind_splicer(), mod_charges(), mod_last_rot_check(), Character::modify_morale(), iuse::molotov_lit(), npc::mug_player(), iuse::multicooker(), Character::mutation_effect(), npc_throw(), on_wield(), iuse::oxygen_bottle(), iuse::pack_item(), target_ui::panel_gun_info(), parse_tags(), petfood(), pick_one_up(), iuse::pickaxe(), iuse::play_game(), avatar_action::plthrow(), iuse::portable_game(), Character::pour_into(), iexamine::pour_into_keg(), npc::pretend_fire(), game::print_items_info(), game::process_artifact(), process_blackpowder_fouling(), process_extinguish(), map::process_fields_in_submap(), process_internal(), process_litcig(), process_tool(), ranged::prompt_select_default_ammo_for(), mattack::pull_metal_weapon(), put_into_vehicle(), item_reload_option::qty(), iuse::radio_mod(), iuse::radiocar(), character_funcs::rate_sleep_spot(), player::reduce_charges(), avatar_action::reload(), bandolier_actor::reload(), reload(), activity_handlers::reload_finish(), remove_radio_mod(), auto_pickup::player_settings::remove_rule(), repair_item_actor::repair(), activity_handlers::repair_item_finish(), iuse::robotcontrol(), map::rotten_item_spawn(), iuse::rpgdie(), examine_item_menu::run(), iuse::seed(), character_funcs::select_ammo(), talk_effect_fun_t::set_bulk_trade_accept(), talk_effect_fun_t::set_consume_item(), set_item_inventory(), set_item_map(), set_item_map_or_vehicle(), set_mtype(), set_next_failure_point(), talk_effect_fun_t::set_u_buy_item(), gun_actor::shoot(), trading_window::show_item_data(), sleep(), smash(), iuse::smoking(), iuse::solarpack(), holster_actor::store(), npc::stow_item(), Character::suffer_from_bad_bionics(), monexamine::take_items_from(), Character::takeoff(), iuse::talking_doll(), tname(), iuse::toggle_heats_food(), tool_info(), iuse::towel_common(), iexamine::tree_maple_tapped(), try_consume(), avatar_funcs::try_disarm_npc(), try_reject_mutagen(), avatar_funcs::try_steal_from_npc(), salvage_actor::try_to_cut_up(), target_ui::uitext_title(), iuse::unfold_generic(), avatar_funcs::unload_item(), iuse::unpack_item(), Character::unwield(), inventory_entry::update_cache(), iuse_transform::use(), countdown_actor::use(), explosion_iuse::use(), unfold_vehicle_iuse::use(), set_transform_iuse::use(), change_scent_iuse::use(), deploy_furn_actor::use(), reveal_map_actor::use(), firestarter_actor::use(), inscribe_actor::use(), holster_actor::use(), ammobelt_actor::use(), heal_actor::use(), place_trap_actor::use(), deploy_tent_actor::use(), saw_barrel_actor::use(), saw_stock_actor::use(), unpack_actor::use(), cast_spell_actor::use(), heal_actor::use_healing_item(), avatar_funcs::use_item(), npc::use_painkiller(), iuse::vibe(), activity_handlers::vibe_do_turn(), Character::wear_item(), iuse::weather_tool(), avatar::wield(), avatar_action::wield(), Character::will_eat(), wind_resist(), debug_menu::wishitem(), memorial_logger::write(), and iuse::xanax().

◆ tool_info()

void item::tool_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3101 of file item.cpp.

3103{
3104 if( !is_tool() ) {
3105 return;
3106 }
3107
3109 if( ammo_capacity() != 0 && parts->test( iteminfo_parts::TOOL_CHARGES ) ) {
3110 info.emplace_back( "TOOL", string_format( _( "<bold>Charges</bold>: %d" ),
3111 ammo_remaining() ) );
3112 }
3113
3114 if( !magazine_integral() ) {
3116 info.emplace_back( "TOOL", _( "Magazine: " ),
3117 string_format( "<stat>%s</stat>", magazine_current()->tname() ) );
3118 }
3119
3121 const std::set<itype_id> compat = magazine_compatible();
3122 info.emplace_back( "TOOL", _( "Compatible magazines: " ),
3123 enumerate_as_string( compat.begin(), compat.end(), []( const itype_id & id ) {
3124 return item::nname( id );
3125 } ) );
3126 }
3127 } else if( ammo_capacity() != 0 && parts->test( iteminfo_parts::TOOL_CAPACITY ) ) {
3128 std::string tmp;
3129 bool bionic_tool = has_flag( flag_USES_BIONIC_POWER );
3130 if( !ammo_types().empty() ) {
3131 //~ "%s" is ammunition type. This types can't be plural.
3132 tmp = vgettext( "Maximum <num> charge of %s.", "Maximum <num> charges of %s.",
3133 ammo_capacity() );
3134 tmp = string_format( tmp, enumerate_as_string( ammo_types().begin(),
3135 ammo_types().end(), []( const ammotype & at ) {
3136 return at->name();
3138
3139 // No need to display max charges, since charges are always equal to bionic power
3140 } else if( !bionic_tool ) {
3141 tmp = vgettext( "Maximum <num> charge.", "Maximum <num> charges.", ammo_capacity() );
3142 }
3143 if( !bionic_tool ) {
3144 info.emplace_back( "TOOL", "", tmp, iteminfo::no_flags, ammo_capacity() );
3145 }
3146 }
3147}

References _, ammo_capacity(), ammo_remaining(), ammo_types(), enumerate_as_string(), flag_USES_BIONIC_POWER(), has_flag(), info(), insert_separation_line(), is_tool(), magazine_compatible(), magazine_current(), magazine_integral(), ammunition_type::name(), iteminfo::no_flags, none, string_format(), iteminfo_query::test(), tname(), TOOL_CAPACITY, TOOL_CHARGES, TOOL_MAGAZINE_COMPATIBLE, TOOL_MAGAZINE_CURRENT, and vgettext().

Referenced by info().

◆ toolmods() [1/2]

std::vector< item * > item::toolmods ( )

Returns all toolmods currently attached to this item (always empty if item not a tool)

Definition at line 5474 of file item.cpp.

5475{
5476 std::vector<item *> res;
5477 if( is_tool() ) {
5478 for( item *e : contents.all_items_top() ) {
5479 if( e->is_toolmod() ) {
5480 res.push_back( e );
5481 }
5482 }
5483 }
5484 return res;
5485}

References item_contents::all_items_top(), contents, and is_tool().

Referenced by ammo_capacity(), ammo_data(), ammo_types(), contents_info(), has_flag(), magazine_compatible(), magazine_default(), magazine_integral(), iuse::remove_all_mods(), tname(), and iuse::toolmod_attach().

◆ toolmods() [2/2]

std::vector< const item * > item::toolmods ( ) const

Definition at line 5487 of file item.cpp.

5488{
5489 std::vector<const item *> res;
5490 if( is_tool() ) {
5491 for( const item *e : contents.all_items_top() ) {
5492 if( e->is_toolmod() ) {
5493 res.push_back( e );
5494 }
5495 }
5496 }
5497 return res;
5498}

References item_contents::all_items_top(), contents, and is_tool().

◆ type_name()

std::string item::type_name ( unsigned int  quantity = 1) const

Name of the item type (not the item), with proper plural.

This is only special when the item itself has a special name ("name" entry in item_tags) or is a named corpse. It's effectively the same as calling nname with the item type id. Use this when the actual item is not meant, for example "The shovel" instead of "Your shovel". Or "The jacket is too small", when it applies to all jackets, not just the one the character tried to wear).

Definition at line 9880 of file item.cpp.

9881{
9882 const auto iter = item_vars.find( "name" );
9883 std::string ret_name;
9884 if( typeId() == itype_blood ) {
9885 if( corpse == nullptr || corpse->id.is_null() ) {
9886 return vpgettext( "item name", "human blood", "human blood", quantity );
9887 } else {
9888 return string_format( vpgettext( "item name", "%s blood",
9889 "%s blood", quantity ),
9890 corpse->nname() );
9891 }
9892 } else if( iter != item_vars.end() ) {
9893 return iter->second;
9894 } else {
9895 ret_name = type->nname( quantity );
9896 }
9897
9898 // Apply conditional names, in order.
9899 for( const conditional_name &cname : type->conditional_names ) {
9900 // Lambda for recursively searching for a item ID among all components.
9901 std::function<bool ( std::list<item> )> component_id_contains =
9902 [&]( std::list<item> components ) {
9903 for( const item &component : components ) {
9904 if( component.typeId().str().find( cname.condition ) != std::string::npos ||
9905 component_id_contains( component.components ) ) {
9906 return true;
9907 }
9908 }
9909 return false;
9910 };
9911 switch( cname.type ) {
9913 if( has_flag( cname.condition ) ) {
9914 ret_name = string_format( cname.name.translated( quantity ), ret_name );
9915 }
9916 break;
9918 if( component_id_contains( components ) ) {
9919 ret_name = string_format( cname.name.translated( quantity ), ret_name );
9920 }
9921 break;
9923 break;
9924 }
9925 }
9926
9927 // Identify who this corpse belonged to, if applicable.
9928 if( corpse != nullptr && has_flag( flag_CORPSE ) ) {
9929 if( corpse_name.empty() ) {
9930 //~ %1$s: name of corpse with modifiers; %2$s: species name
9931 ret_name = string_format( pgettext( "corpse ownership qualifier", "%1$s of a %2$s" ),
9932 ret_name, corpse->nname() );
9933 } else {
9934 //~ %1$s: name of corpse with modifiers; %2$s: proper name; %3$s: species name
9935 ret_name = string_format( pgettext( "corpse ownership qualifier", "%1$s of %2$s, %3$s" ),
9936 ret_name, corpse_name, corpse->nname() );
9937 }
9938 }
9939
9940 return ret_name;
9941}
@ COMPONENT_ID
Definition: itype.h:777
@ FLAG
Definition: itype.h:776
@ num_condition_types
Definition: itype.h:778
std::string condition
Definition: itype.h:791
translation name
Definition: itype.h:794
condition_type type
Definition: itype.h:789
std::vector< conditional_name > conditional_names
Definition: itype.h:886

References COMPONENT_ID, components, conditional_name::condition, itype::conditional_names, corpse, corpse_name, FLAG, flag_CORPSE(), has_flag(), mtype::id, string_id< T >::is_null(), item_vars, itype_blood, conditional_name::name, itype::nname(), mtype::nname(), num_condition_types, pgettext(), string_format(), translation::translated(), type, conditional_name::type, typeId(), and vpgettext().

Referenced by advanced_inventory::action_examine(), Character::can_wear(), game_menus::inv::compare(), avatar::do_read(), talk_function::field_harvest(), activity_handlers::fill_liquid_do_turn(), npc::finish_read(), character_funcs::fmt_wielded_weapon(), trading_window::get_var_trade(), Character::is_snuggling(), inscribe_actor::item_inscription(), label(), game::list_items(), Character::pour_into(), avatar::read(), bandolier_actor::reload(), game_menus::inv::repair(), examine_item_menu::run(), trading_window::show_item_data(), skim_book_msg(), Character::suffer_from_schizophrenia(), tname(), consume_drug_iuse::use(), place_monster_iuse::use(), and bandolier_actor::use().

◆ typeId()

const itype_id & item::typeId ( ) const

return the unique identifier of the items underlying type

Definition at line 8374 of file item.cpp.

8375{
8376 return type ? type->get_id() : itype_id::NULL_ID();
8377}

References itype::get_id(), string_id< itype >::NULL_ID(), and type.

Referenced by computer_session::action_blood_anal(), computer_session::action_data_anal(), add_disassemblables(), inventory::add_item_by_items_type_cache(), map::add_item_or_charges(), add_rain_to_container(), item_pricing::adjust_values(), vehicle_part::ammo_current(), ammo_set(), amount_of_internal(), armor_fit_info(), inventory::assign_empty_invlet(), iexamine::autodoc(), basic_info(), iuse::bell(), mattack::bio_op_takedown(), book_info(), Character::can_fuel_bionic_with(), vehicle_part::can_reload(), bandolier_actor::can_store(), Character::can_use_heal_item(), Character::can_wear(), Character::can_wield(), color_in_inventory(), combat_info(), crafting::complete_disassemble(), Character::compute_nutrient_range(), prepared_item_consumption::consume(), vehicle_part::consume_energy(), consumption_event::consumption_event(), mattack::copbot(), map::create_burnproducts(), iuse::directional_antenna(), disassembly_info(), Character::dismount(), iuse::dive_tank(), avatar::do_read(), npc::do_reload(), anonymous_namespace{iexamine.cpp}::atm_menu::do_transfer_all_money(), editmap::draw_main_ui_overlay(), iuse::ecig(), iuse::ehandcuffs(), explosion_handler::emp_blast(), computer_session::failure_destroy_blood(), computer_session::failure_destroy_data(), farm_valid_seed(), fetch_activity(), talk_function::field_harvest(), talk_function::field_plant(), activity_handlers::fill_liquid_do_turn(), fill_with(), final_info(), character_funcs::find_ammo_helper(), iexamine::fireplace(), food_info(), Character::fuel_bionic_with(), Character::fun_for(), iexamine::fvat_empty(), iuse::geiger(), json_talk_topic::gen_responses(), generic_multi_activity_do(), Character::get_acquirable_energy(), inventory::get_binned_items(), Character::get_bionic_fueled_with(), character_funcs::get_book_fun_for(), read_inventory_preset::get_denial(), bionic_install_preset::get_failure_chance(), Character::get_overlay_ids(), disassemble_inventory_preset::get_recipe(), get_remaining_capacity_for_liquid(), json_item_substitution::get_substitution(), get_uncraft_components(), give_item_to(), mattack::grab(), iuse::granade_act(), Character::has_active_item(), inventory::has_enough_painkiller(), Character::i_add(), Character::i_add_to_container(), monster::init_from_item(), init_memory_card_with_random_stuff(), io(), advanced_inv_area::is_container_valid(), character_funcs::is_fun_to_read(), is_funnel_container(), is_gunmod_compatible(), read_inventory_preset::is_known(), is_null(), is_reloadable_helper(), ma_requirements::is_valid_character(), item(), Character::item_handling_cost(), iexamine::keg(), ma_style_callback::key(), aim_activity_actor::load_RAS_weapon(), iuse::lumber(), iuse::marloss(), iuse::marloss_gel(), iuse::marloss_seed(), to_cbc_migration::migration_required(), iuse::mind_splicer(), Item_modifier::modify(), advanced_inventory::move_content(), iuse::mp3(), iuse::mp3_on(), item_stack::only_item(), iuse::pack_cbm(), iuse::pack_item(), iexamine::pedestal_temple(), iexamine::pedestal_wyrm(), peek_related_recipe(), pick_usb(), avatar_action::plthrow(), iexamine::pour_into_keg(), process_extinguish(), process_litcig(), examine_item_menu::rate_action_disassemble(), examine_item_menu::rate_action_read(), avatar::read(), game_menus::inv::reassign_letter(), reload(), activity_handlers::reload_finish(), repair_item_actor::repair_recipe_difficulty(), mattack::riotbot(), iuse::rm13armor_off(), iuse::rm13armor_on(), advanced_inv_area::set_container(), talk_effect_fun_t::set_remove_item_with(), player_morale::set_worn(), iuse::smoking(), iuse::solarpack(), iuse::solarpack_off(), Character::suffer_from_bad_bionics(), Character::suffer_from_radiation(), iuse::talking_doll(), tname(), iuse::toolmod_attach(), toolweapon_off(), toolweapon_on(), iuse::towel_common(), npc_trading::transfer_items(), iexamine::tree_maple_tapped(), disassemble_activity_actor::try_start_single(), salvage_actor::try_to_cut_up(), character_funcs::try_wield_contents(), type_name(), iuse::unpack_item(), inventory::update_cache_with_item(), inventory::update_invlet(), unfold_vehicle_iuse::use(), musical_instrument_actor::use(), unpack_actor::use(), use_amount_internal(), map::use_amount_square(), Character::use_charges(), map::use_charges(), avatar_funcs::use_item(), vehicle::use_washing_machine(), npc::value(), vehicle_part::vehicle_part(), volume(), iuse::water_purifier(), martialart::weapon_valid(), Character::wear_item(), iuse::weather_tool(), avatar::wield(), npc::wield_better_weapon(), and wind_resist().

◆ units_remaining()

int item::units_remaining ( const Character ch,
int  limit = INT_MAX 
) const

How many units (ammo or charges) are remaining?

Parameters
chcharacter responsible for invoking the item
limitstop searching after this many units found
Note
also checks availability of UPS charges if applicable

Definition at line 8008 of file item.cpp.

8009{
8010 if( count_by_charges() ) {
8011 return std::min( static_cast<int>( charges ), limit );
8012 }
8013
8014 int res = ammo_remaining();
8015 if( res < limit && is_power_armor() ) {
8017 res += std::max( ch.charges_of( itype_UPS, limit - res ), ch.charges_of( itype_bio_armor,
8018 limit - res ) );
8019 } else if( character_funcs::can_interface_armor( ch ) ) {
8020 res += ch.charges_of( itype_bio_armor, limit - res );
8021 } else {
8022 res += ch.charges_of( itype_UPS, limit - res );
8023 }
8024 } else if( res < limit && has_flag( flag_USE_UPS ) ) {
8025 res += ch.charges_of( itype_UPS, limit - res );
8026 }
8027
8028 return std::min( static_cast<int>( res ), limit );
8029}
int charges_of(const itype_id &what, int limit=INT_MAX, const std::function< bool(const item &)> &filter=return_true< item >, std::function< void(int)> visitor=nullptr) const
Count maximum available charges from this instance and any contained items.
Definition: visitable.cpp:946

References ammo_remaining(), character_funcs::can_interface_armor(), charges, visitable< T >::charges_of(), count_by_charges(), flag_USE_UPS(), has_flag(), is_power_armor(), itype_bio_armor, and itype_UPS.

Referenced by iuse::portable_game(), units_sufficient(), iuse_transform::use(), and set_transform_iuse::use().

◆ units_sufficient()

bool item::units_sufficient ( const Character ch,
int  qty = -1 
) const

Check if item has sufficient units (ammo or charges) remaining.

Parameters
chCharacter to check (used if ammo is UPS charges)
qtyunits required, if unspecified use item default

Definition at line 8031 of file item.cpp.

8032{
8033 if( qty < 0 ) {
8034 qty = count_by_charges() ? 1 : ammo_required();
8035 }
8036
8037 return units_remaining( ch, qty ) == qty;
8038}
int units_remaining(const Character &ch, int limit=INT_MAX) const
How many units (ammo or charges) are remaining?
Definition: item.cpp:8008

References ammo_required(), count_by_charges(), and units_remaining().

Referenced by cauterize_actor::can_use(), iuse::gun_repair(), iuse::mp3(), iuse::multicooker(), iuse::noise_emitter_off(), iuse::radglove(), iuse::radio_off(), iuse::radiocontrol(), iuse::remoteveh(), activity_handlers::repair_item_finish(), iuse::robotcontrol(), iuse::shocktonfa_off(), iuse::shocktonfa_on(), iuse::talking_doll(), iuse::tazer(), toolweapon_off(), toolweapon_on(), iuse::vibe(), and iuse::water_purifier().

◆ unset_flag()

item & item::unset_flag ( const std::string &  flag)

◆ unset_flags()

void item::unset_flags ( )

Removes all item specific flags.

Definition at line 5313 of file item.cpp.

5314{
5315 item_tags.clear();
5316}

References item_tags.

Referenced by iuse::camera(), einkpc_download_memory_card(), and iuse::einktabletpc().

◆ update_clothing_mod_val()

void item::update_clothing_mod_val ( )

Definition at line 10179 of file item.cpp.

10180{
10183 type );
10184 float tmp = 0.0;
10185 for( const clothing_mod &cm : clothing_mods::get_all_with( type ) ) {
10186 if( has_own_flag( cm.flag ) ) {
10187 tmp += cm.get_mod_val( type, *this );
10188 }
10189 }
10190 set_var( key, tmp );
10191 }
10192}
clothing_mod_type
Definition: clothing_mod.h:16
const std::vector< clothing_mod > & get_all_with(clothing_mod_type type)
constexpr std::array< clothing_mod_type, 9 > all_clothing_mod_types
Definition: clothing_mod.h:63

References clothing_mods::all_clothing_mod_types, CLOTHING_MOD_VAR_PREFIX(), clothing_mods::get_all_with(), has_own_flag(), set_var(), clothing_mods::string_from_clothing_mod_type(), and type.

Referenced by sew_advanced_actor::use().

◆ use_amount()

bool item::use_amount ( const itype_id it,
int &  quantity,
std::list< item > &  used,
const std::function< bool(const item &)> &  filter = return_true<item> 
)

Consume a specific amount of items of a specific type.

This includes this item, and any of its contents (recursively).

See also
item::use_charges - this is similar for items, not charges.
Parameters
itType of consumable item.
quantityHow much to consumed.
usedOn success all consumed items will be stored here.
filterMust return true for use to occur.

Definition at line 8512 of file item.cpp.

8514{
8515 // Remember quantity so that we can unseal self
8516 int old_quantity = quantity;
8517 std::vector<item *> removed_items;
8518 // First, check contents
8520 [&]( item * a ) {
8521 // visit_items checks the item itself first. we want to do its contents first.
8522 if( a == this ) {
8523 return VisitResponse::NEXT;
8524 }
8525 if( a->use_amount_internal( it, quantity, used, filter ) ) {
8526 removed_items.emplace_back( a );
8527 return VisitResponse::SKIP;
8528 }
8529 return VisitResponse::NEXT;
8530 } );
8531
8532 for( item *remove : removed_items ) {
8533 remove_item( *remove );
8534 }
8535
8536 if( quantity != old_quantity ) {
8538 }
8539 return use_amount_internal( it, quantity, used, filter );
8540}
bool use_amount_internal(const itype_id &it, int &quantity, std::list< item > &used, const std::function< bool(const item &)> &filter=return_true< item >)
Definition: item.cpp:8542
constexpr double a
Definition: magic.cpp:1030

References a, NEXT, on_contents_changed(), visitable< item >::remove_item(), use_amount_internal(), and visitable< item >::visit_items().

◆ use_amount_internal()

bool item::use_amount_internal ( const itype_id it,
int &  quantity,
std::list< item > &  used,
const std::function< bool(const item &)> &  filter = return_true<item> 
)
private

Definition at line 8542 of file item.cpp.

8544{
8545 if( typeId() == it && quantity > 0 && filter( *this ) ) {
8546 used.push_back( *this );
8547 quantity--;
8548 return true;
8549 } else {
8550 return false;
8551 }
8552}

References typeId().

Referenced by use_amount().

◆ use_charges()

bool item::use_charges ( const itype_id what,
int &  qty,
std::list< item > &  used,
const tripoint pos,
const std::function< bool(const item &)> &  filter = return_true<item> 
)

Consumes specified charges (or fewer) from this and any contained items.

Parameters
whatspecific type of charge required, e.g. 'battery'
qtymaximum charges to consume. On return set to number of charges not found (or zero)
usedfilled with duplicates of each item that provided consumed charges
posposition at which the charges are being consumed
filterMust return true for use to occur.
Returns
true if this item should be deleted (count-by-charges items with no remaining charges)

Definition at line 8632 of file item.cpp.

8634{
8635 std::vector<item *> del;
8636
8637 visit_items( [&what, &qty, &used, &pos, &del, &filter]( item * e, item * parent ) {
8638 if( qty == 0 ) {
8639 // found sufficient charges
8640 return VisitResponse::ABORT;
8641 }
8642
8643 if( !filter( *e ) ) {
8644 return VisitResponse::NEXT;
8645 }
8646
8647 if( e->is_tool() ) {
8648 if( e->typeId() == what ) {
8649 int n = std::min( e->ammo_remaining(), qty );
8650 qty -= n;
8651
8652 used.push_back( item( *e ).ammo_set( e->ammo_current(), n ) );
8653 e->ammo_consume( n, pos );
8654 }
8655 return VisitResponse::SKIP;
8656
8657 } else if( e->count_by_charges() ) {
8658 if( e->typeId() == what ) {
8659
8660 // if can supply excess charges split required off leaving remainder in-situ
8661 item obj = e->split( qty );
8662 if( parent ) {
8663 parent->on_contents_changed();
8664 }
8665 if( !obj.is_null() ) {
8666 used.push_back( obj );
8667 qty = 0;
8668 return VisitResponse::ABORT;
8669 }
8670
8671 qty -= e->charges;
8672 used.push_back( *e );
8673 del.push_back( e );
8674 }
8675 // items counted by charges are not themselves expected to be containers
8676 return VisitResponse::SKIP;
8677 }
8678
8679 // recurse through any nested containers
8680 return VisitResponse::NEXT;
8681 } );
8682
8683 bool destroy = false;
8684 for( item *e : del ) {
8685 if( e == this ) {
8686 destroy = true; // cannot remove ourselves...
8687 } else {
8688 remove_item( *e );
8689 }
8690 }
8691
8692 return destroy;
8693}

References ABORT, count_by_charges(), is_tool(), NEXT, SKIP, and visitable< item >::visit_items().

Referenced by Character::use_charges(), and use_charges_from_furn().

◆ validate_ownership()

void item::validate_ownership ( ) const

Definition at line 1294 of file item.cpp.

1295{
1296 if( !old_owner.is_null() && !g->faction_manager_ptr->get( old_owner, false ) ) {
1298 }
1299 if( !owner.is_null() && !g->faction_manager_ptr->get( owner, false ) ) {
1300 remove_owner();
1301 }
1302}
void remove_old_owner() const
Definition: item.h:2022
void remove_owner() const
Definition: item.h:2029

References g, string_id< T >::is_null(), old_owner, owner, remove_old_owner(), and remove_owner().

Referenced by get_old_owner(), and get_owner().

◆ volume()

units::volume item::volume ( bool  integral = false) const

Total volume of an item accounting for all contained/integrated items NOTE: Result is rounded up to next nearest milliliter when working with stackable (count_by_charges) items that have fractional volume per charge.

If trying to determine how many of an item can fit in a given space, charges_per_volume should be used instead.

Parameters
integralif true return effective volume if this item was integrated into another

Definition at line 5129 of file item.cpp.

5130{
5131 if( is_null() ) {
5132 return 0_ml;
5133 }
5134
5135 if( is_corpse() ) {
5136 return corpse_volume( corpse );
5137 }
5138
5139 if( is_craft() ) {
5140 units::volume ret = 0_ml;
5141 for( const item &it : components ) {
5142 ret += it.volume();
5143 }
5144 return ret;
5145 }
5146
5147 const int local_volume = get_var( "volume", -1 );
5149 if( local_volume >= 0 ) {
5150 ret = local_volume * units::legacy_volume_factor;
5151 } else if( integral ) {
5153 } else {
5154 ret = type->volume;
5155 }
5156
5157 if( count_by_charges() || made_of( LIQUID ) ) {
5159 ( charges );
5160 if( type->stack_size <= 0 ) {
5161 debugmsg( "Item type %s has invalid stack_size %d", typeId().str(), type->stack_size );
5162 ret = num;
5163 } else {
5164 ret = num / type->stack_size;
5165 if( num % type->stack_size != 0_ml ) {
5166 ret += 1_ml;
5167 }
5168 }
5169 }
5170
5171 // Non-rigid items add the volume of the content
5172 if( !type->rigid ) {
5174 }
5175
5176 // Some magazines sit (partly) flush with the item so add less extra volume
5177 if( magazine_current() != nullptr ) {
5178 ret += std::max( magazine_current()->volume() - type->magazine_well, 0_ml );
5179 }
5180
5181 if( is_gun() ) {
5182 for( const item *elem : gunmods() ) {
5183 ret += elem->volume( true );
5184 }
5185
5186 // TODO: implement stock_length property for guns
5188 // consider only the base size of the gun (without mods)
5189 ret -= ( type->volume / 3 );
5190 }
5191
5193 ret -= type->gun->barrel_length;
5194 }
5195 }
5196
5197 return ret;
5198}
static const std::string flag_COLLAPSIBLE_STOCK("COLLAPSIBLE_STOCK")
units::volume magazine_well
Volume above which the magazine starts to protrude from the item and add extra volume.
Definition: itype.h:994
units::volume integral_volume
Space consumed when integrated as part of another item (defaults to volume) CAUTION: value given is f...
Definition: itype.h:947

References charges, components, contents, corpse, corpse_volume(), count_by_charges(), debugmsg, flag_COLLAPSIBLE_STOCK(), get_var(), itype::gun, gunmod_find(), gunmods(), has_flag(), itype::integral_volume, is_corpse(), is_craft(), is_gun(), is_null(), item_contents::item_size_modifier(), itype_barrel_small, units::legacy_volume_factor, LIQUID, made_of(), magazine_current(), itype::magazine_well, num, cata::hash64_detail::ret, itype::rigid, itype::stack_size, type, typeId(), volume(), and itype::volume.

Referenced by activity_on_turn_move_loot(), map::add_item_or_charges(), ranged::aim_cap_from_volume(), attack_cost(), basic_info(), veh_interact::calc_overview(), holster_actor::can_holster(), charges_per_volume(), comestible_inventory_preset::comestible_inventory_preset(), vehicle_part::consume_energy(), salvage_actor::cut_up(), Character::deal_damage(), npc::drop_items(), drop_or_embed_projectile(), fetch_activity(), iexamine::fvat_empty(), Character::get_acquirable_energy(), get_encumber_when_containing(), ranged::get_weapon_dispersion(), monexamine::give_items_to(), repair_item_actor::handle_components(), Character::item_handling_cost(), mdeath::jabberwock(), iexamine::keg(), Character::melee_special_effects(), move_cost_cart(), move_cost_inv(), iexamine::nanofab(), npc_pickup_from_stack(), pickup::obtain_and_tokenize_items(), Character::on_dodge(), on_wield(), vehicle::operate_scoop(), pick_one_up(), pickup::pick_up(), iexamine::pour_into_keg(), Character::power_rating(), process_corpse(), iuse::radiocar(), ready_to_revive(), pickup::reorder_for_dropping(), item_pricing::set_values(), npc::shop_restock(), smash(), holster_actor::store(), npc::stow_item(), stumble(), Character::takeoff(), ranged::throw_item(), Character::throw_range(), ranged::throwing_dispersion(), salvage_actor::time_to_cut_up(), tname(), salvage_actor::try_to_cut_up(), Character::update_bodytemp(), salvage_actor::valid_to_cut_up(), volume(), inventory::volume_without(), and wash_items().

◆ weight()

units::mass item::weight ( bool  include_contents = true,
bool  integral = false 
) const

Definition at line 4983 of file item.cpp.

4984{
4985 if( is_null() ) {
4986 return 0_gram;
4987 }
4988
4989 // Items that don't drop aren't really there, they're items just for ease of implementation
4990 if( has_flag( flag_NO_DROP ) ) {
4991 return 0_gram;
4992 }
4993
4994 if( is_craft() ) {
4995 units::mass ret = 0_gram;
4996 for( const item &it : components ) {
4997 ret += it.weight();
4998 }
4999 return ret;
5000 }
5001
5003 std::string local_str_mass = integral ? get_var( "integral_weight" ) : get_var( "weight" );
5004 if( local_str_mass.empty() ) {
5005 ret = integral ? type->integral_weight : type->weight;
5006 } else {
5007 ret = units::from_milligram( std::stoll( local_str_mass ) );
5008 }
5009
5010 if( has_flag( flag_REDUCED_WEIGHT ) ) {
5011 ret *= 0.75;
5012 }
5013
5014 // if this is a gun apply all of its gunmods' weight multipliers
5015 if( is_gun() ) {
5016 for( const item *mod : gunmods() ) {
5017 ret *= mod->type->gunmod->weight_multiplier;
5018 }
5019 }
5020
5021 if( count_by_charges() ) {
5022 ret *= charges;
5023
5024 } else if( is_corpse() ) {
5025 assert( corpse ); // To appease static analysis
5026 ret = corpse->weight;
5028 ret *= 0.75;
5029 }
5030 if( has_flag( flag_QUARTERED ) ) {
5031 ret /= 4;
5032 }
5033 if( has_flag( flag_GIBBED ) ) {
5034 ret *= 0.85;
5035 }
5036 if( has_flag( flag_SKINNED ) ) {
5037 ret *= 0.85;
5038 }
5039
5040 } else if( magazine_integral() && !is_magazine() ) {
5041 if( ammo_current() == itype_plut_cell ) {
5042 units::mass w = ( *ammo_types().begin() )->default_ammotype()->weight;
5044 } else if( ammo_data() ) {
5046 }
5047 }
5048
5049 // if this is an ammo belt add the weight of any implicitly contained linkages
5050 if( is_magazine() && type->magazine->linkage ) {
5051 item links( *type->magazine->linkage );
5052 links.charges = ammo_remaining();
5053 ret += links.weight();
5054 }
5055
5056 // reduce weight for sawn-off weapons capped to the apportioned weight of the barrel
5058 const units::volume b = type->gun->barrel_length;
5059 const units::mass max_barrel_weight = units::from_gram( to_milliliter( b ) );
5060 const units::mass barrel_weight = units::from_gram( b.value() * type->weight.value() /
5061 type->volume.value() );
5062 ret -= std::min( max_barrel_weight, barrel_weight );
5063 }
5064
5065 if( is_gun() ) {
5066 for( const item *elem : gunmods() ) {
5067 ret += elem->weight( true, true );
5068 }
5069 if( !magazine_integral() && magazine_current() ) {
5070 ret += std::max( magazine_current()->weight(), 0_gram );
5071 }
5072 } else if( include_contents ) {
5074 }
5075
5076 return ret;
5077}
units::mass item_weight_modifier() const
static const std::string flag_NO_DROP("NO_DROP")
static const std::string flag_REDUCED_WEIGHT("REDUCED_WEIGHT")
static const itype_id itype_plut_cell("plut_cell")
constexpr double b
Definition: magic.cpp:1031
constexpr value_type to_milliliter(const quantity< value_type, volume_in_milliliter_tag > &v)
Definition: units_volume.h:38
constexpr quantity< value_type, mass_in_milligram_tag > from_milligram(const value_type v)
Definition: units_mass.h:34
constexpr quantity< value_type, mass_in_milligram_tag > from_gram(const value_type v)
Definition: units_mass.h:41
units::mass integral_weight
Weight difference with the part it replaces for mods.
Definition: itype.h:935
units::mass weight
Definition: mtype.h:264

References ammo_current(), ammo_data(), ammo_remaining(), ammo_types(), b, charges, components, contents, corpse, count_by_charges(), flag_FIELD_DRESS(), flag_FIELD_DRESS_FAILED(), flag_GIBBED(), flag_NO_DROP(), flag_QUARTERED(), flag_REDUCED_WEIGHT(), flag_SKINNED(), units::from_gram(), units::from_milligram(), get_var(), itype::gun, gunmod_find(), gunmods(), has_flag(), itype::integral_weight, is_corpse(), is_craft(), is_gun(), is_magazine(), is_null(), item_contents::item_weight_modifier(), itype_barrel_small, itype_plut_cell, itype::magazine, magazine_current(), magazine_integral(), PLUTONIUM_CHARGES, cata::hash64_detail::ret, units::to_milliliter(), type, units::quantity< V, U >::value(), itype::volume, weight(), itype::weight, and mtype::weight.

Referenced by monexamine::add_armor(), attack_cost(), basic_info(), can_do_activity_there(), holster_actor::can_holster(), Character::can_pick_weight(), veh_interact::can_remove_part(), pickup::cost_to_move_item(), npc::drop_items(), fetch_activity(), funnel_charges_per_turn(), Character::get_acquirable_energy(), Character::get_weight(), monexamine::give_items_to(), is_two_handed(), lift_strength(), Character::melee_attack(), npc_pickup_from_stack(), pick_one_up(), pickup::pick_up(), advanced_inventory::query_charges(), iuse::radiocar(), item_pricing::set_values(), smash(), holster_actor::store(), stumble(), ranged::throw_item(), Character::throw_range(), ranged::throwing_dispersion(), trap::triggered_by_item(), veh_interact::update_part_requirements(), weight(), Character::weight_carried_reduced_by(), and inventory::weight_without().

◆ wheel_area()

int item::wheel_area ( ) const

Returns the total area of this wheel or 0 if it isn't one.

Definition at line 6836 of file item.cpp.

6837{
6838 return is_wheel() ? type->wheel->diameter * type->wheel->width : 0;
6839}

References is_wheel(), type, and itype::wheel.

◆ will_explode_in_fire()

bool item::will_explode_in_fire ( ) const

Definition at line 8750 of file item.cpp.

8751{
8752 if( type->explode_in_fire ) {
8753 return true;
8754 }
8755
8756 if( type->ammo && ( type->ammo->special_cookoff || type->ammo->cookoff ) ) {
8757 return true;
8758 }
8759
8760 // Most containers do nothing to protect the contents from fire
8761 if( !is_magazine() || !type->magazine->protects_contents ) {
8762 return has_item_with( [&]( const item & it ) {
8763 return this != &it && it.will_explode_in_fire();
8764 } );
8765 }
8766
8767 return false;
8768}
bool will_explode_in_fire() const
Definition: item.cpp:8750
bool explode_in_fire
Definition: itype.h:915

References itype::ammo, itype::explode_in_fire, visitable< item >::has_item_with(), is_magazine(), itype::magazine, type, and will_explode_in_fire().

Referenced by will_explode_in_fire().

◆ wind_resist()

int item::wind_resist ( ) const

How resistant clothes made of this material are to wind (0-100)

Definition at line 6805 of file item.cpp.

6806{
6807 std::vector<const material_type *> materials = made_of_types();
6808 if( materials.empty() ) {
6809 debugmsg( "Called item::wind_resist on an item (%s [%s]) made of nothing!", tname(), typeId() );
6810 return 99;
6811 }
6812
6813 int best = -1;
6814 for( const material_type *mat : materials ) {
6815 std::optional<int> resistance = mat->wind_resist();
6816 if( resistance && *resistance > best ) {
6817 best = *resistance;
6818 }
6819 }
6820
6821 // Default to 99% effective
6822 if( best == -1 ) {
6823 return 99;
6824 }
6825
6826 return best;
6827}

References debugmsg, made_of_types(), tname(), and typeId().

Referenced by wind_resistance_from_item_list().

Member Data Documentation

◆ activated_by

safe_reference<Character> item::activated_by

Definition at line 2238 of file item.h.

Referenced by detonate(), itype::invoke(), and explosion_iuse::use().

◆ active

bool item::active = false

Definition at line 2237 of file item.h.

Referenced by activate(), Character::activate_bionic(), map::add_item(), npc::alt_attack(), iexamine::autodoc(), basic_info(), burn(), iuse::c4(), iuse::cable_attach(), holster_actor::can_holster(), countdown_actor::can_use(), check_litcig(), color_in_inventory(), Character::consume_remote_fuel(), deactivate(), mdeath::detonate(), iuse::dive_tank(), iuse::ehandcuffs(), iuse::einktabletpc(), explosion_handler::emp_blast(), Character::find_remote_fuel(), iuse::firecracker(), iuse::firecracker_pack(), iuse::fish_trap(), iuse::gasmask(), iuse::geiger(), iuse::granade(), Character::has_active_item(), io(), enchantment::is_active(), item(), mattack::kamikaze(), make_gun_projectile(), activity_handlers::make_zlave_finish(), iuse::mininuke(), iuse::molotov_lit(), iuse::mp3(), iuse::mp3_on(), iuse::multicooker(), needs_processing(), iuse::noise_emitter_off(), iuse::noise_emitter_on(), on_takeoff(), on_wear(), iuse::pack_item(), process_extinguish(), process_internal(), process_litcig(), process_tool(), process_UPS(), process_wet(), vehicle_part::properties_to_item(), iuse::radio_off(), iuse::radio_on(), iuse::radiocar(), iuse::radiocaron(), iuse::radiocontrol(), read(), iuse::remoteveh(), reset_cable(), mattack::riotbot(), iuse::rm13armor_off(), iuse::rm13armor_on(), iuse::shocktonfa_off(), iuse::shocktonfa_on(), sleep(), iuse::smoking(), iuse::solarpack_off(), stacks_with(), holster_actor::store(), ranged::throw_item(), iuse::throwable_extinguisher_act(), tname(), toolweapon_off(), toolweapon_on(), iuse::tow_attach(), iuse::towel_common(), avatar_funcs::unload_item(), iuse::unpack_item(), iuse_transform::use(), countdown_actor::use(), fireweapon_off_actor::use(), musical_instrument_actor::use(), and npc::value().

◆ anchor

safe_reference_anchor item::anchor
private

Definition at line 2169 of file item.h.

Referenced by get_safe_reference().

◆ bday

time_point item::bday
private

The time the item was created.

Definition at line 2227 of file item.h.

Referenced by birthday(), io(), item(), legacy_fast_forward_time(), and set_birthday().

◆ burnt

int item::burnt = 0

◆ charges

int item::charges

Definition at line 2199 of file item.h.

Referenced by iuse::acidbomb_act(), act_vehicle_siphon(), Character::activate_bionic(), activity_on_turn_wear(), vehicle::add_charges(), vehicle::add_item(), map::add_item_or_charges(), avatar_funcs::add_or_drop_with_msg(), add_rain_to_container(), ammo_consume(), vehicle_part::ammo_consume(), ammo_remaining(), vehicle_part::ammo_remaining(), ammo_set(), ammo_unset(), item_stack::amount_can_fit(), jmapgen_liquid_item::apply(), are_requirements_nearby(), iuse::arrow_flammable(), basic_info(), burn(), iuse::c4(), bandolier_actor::can_store(), fireweapon_off_actor::can_use(), manualnoise_actor::can_use(), comestible_inventory_preset::comestible_inventory_preset(), complete_craft(), crafting::complete_disassemble(), veh_interact::complete_vehicle(), Character::consume_charges(), vehicle_part::consume_energy(), Character::consume_item(), liquid_handler::consume_liquid(), Character::consume_med(), game_menus::inv::container_for(), count(), activity_handlers::craft_do_turn(), recipe::create_byproducts(), recipe::create_result(), recipe::create_results(), detonate(), mdeath::detonate(), display_name(), iuse::dive_tank(), anonymous_namespace{iexamine.cpp}::atm_menu::do_purchase_card(), npc::do_reload(), veh_interact::do_siphon(), anonymous_namespace{iexamine.cpp}::atm_menu::do_transfer_all_money(), move_items_activity_actor::do_turn(), throw_activity_actor::do_turn(), anonymous_namespace{iexamine.cpp}::atm_menu::do_withdraw_money(), map::draw_lab(), iuse::ehandcuffs(), explosion_handler::emp_blast(), iuse::eyedrops(), farm_action(), Character::feed_furnace_with(), fetch_activity(), talk_function::field_harvest(), activity_handlers::fill_liquid_do_turn(), fill_with(), final_info(), wash_activity_actor::finish(), heal_actor::finish_using(), iuse::firecracker(), iuse::firecracker_act(), iuse::firecracker_pack(), iuse::firecracker_pack_act(), iuse::fish_trap(), character_funcs::fmt_wielded_weapon(), food_info(), for_each_item_in_both(), inventory::form_from_map(), Character::fuel_bionic_with(), funnel_charges_per_turn(), iexamine::fvat_empty(), iexamine::fvat_full(), iuse::gasmask(), Character::get_acquirable_energy(), activity_handlers::repair_activity_hack::anonymous_namespace{activity_handlers.cpp}::get_fake_tool(), iexamine::get_harvest_items(), liquid_handler::get_liquid_target(), get_remaining_capacity_for_liquid(), inventory_entry::get_selected_charges(), json_item_substitution::get_substitution(), monexamine::give_items_to(), iuse::granade(), iuse::granade_act(), iuse::grenade_inc_act(), hackveh(), liquid_handler::handle_all_liquid(), liquid_handler::handle_liquid_from_container(), pickup::handle_spillable_contents(), has_infinite_charges(), Character::i_add_to_container(), io(), item(), Character::item_reload_cost(), iexamine::keg(), med_info(), merge_charges(), Item_factory::migrate_item(), activity_handlers::milk_finish(), iuse::mininuke(), mod_charges(), mod_damage(), Item_modifier::modify(), iuse::molotov_lit(), advanced_inventory::move_all_items(), advanced_inventory::move_content(), move_item(), iuse::multicooker(), npc_throw(), vehicle::operate_planter(), operator<(), parse_tags(), iexamine::pay_gas(), liquid_handler::perform_liquid_transfer(), pick_one_up(), pickup::pick_up(), map::place_gas_pump(), map::place_toilet(), Character::pour_into(), iexamine::pour_into_keg(), advanced_inventory::print_items(), game::process_artifact(), process_cable(), Character::process_items(), relic_funcs::process_recharge_entry(), map::produce_sap(), vehicle_part::properties_to_item(), item_reload_option::qty(), advanced_inventory::query_charges(), player::reduce_charges(), bandolier_actor::reload(), reload(), remove_ammo(), reset_cable(), mattack::riotbot(), talk_effect_fun_t::set_bulk_trade_accept(), set_countdown(), iexamine::sign(), character_funcs::siphon(), smoker_activate(), map::spawn_an_item(), spell_effect::spawn_ethereal_item(), split(), stacks_with(), Character::suffer_from_bad_bionics(), iuse::tazer2(), Character::throw_range(), iuse::throwable_extinguisher_act(), ranged::throwing_dispersion(), tname(), npc_trading::trade(), npc_trading::transfer_items(), iexamine::tree_maple_tapped(), try_consume(), try_fuel_fire(), units_remaining(), avatar_funcs::unload_item(), inventory::update_quality_cache(), explosion_iuse::use(), place_monster_iuse::use(), fireweapon_off_actor::use(), fireweapon_on_actor::use(), manualnoise_actor::use(), bandolier_actor::use(), emit_actor::use(), sew_advanced_actor::use(), basecamp::use_charges(), map::use_charges(), use_charges_from_furn(), iexamine::use_furn_fake_item(), volume(), iuse::water_purifier(), weight(), Character::weight_carried_reduced_by(), debug_menu::wishitem(), and memorial_logger::write().

◆ components

◆ contents

item_contents item::contents

Definition at line 2161 of file item.h.

Referenced by Character::absorb_hit(), act_vehicle_siphon(), computer_session::action_blood_anal(), computer_session::action_data_anal(), actualize_rot(), vehicle::add_item(), add_rain_to_container(), allow_crafting_component(), ammo_consume(), vehicle_part::ammo_consume(), vehicle_part::ammo_current(), ammo_data(), ammo_remaining(), vehicle_part::ammo_remaining(), vehicle_part::ammo_set(), ammo_unset(), vehicle_part::ammo_unset(), map::bash_items(), iuse::blood_draw(), activity_handlers::butcher_finish(), item_location::impl::item_in_container::calc_index(), veh_interact::calc_overview(), item_funcs::can_be_unloaded(), Character::can_consume(), can_holster(), bandolier_actor::can_store(), can_unload_liquid(), casings_handle(), complete_craft(), veh_interact::complete_vehicle(), Character::compute_nutrient_range(), Character::consume(), npc::consume_cbm_items(), vehicle_part::consume_energy(), contents_info(), contents_made_of(), salvage_actor::cut_up(), damage_item(), item_location::deserialize(), deserialize(), detonate(), display_name(), veh_interact::do_siphon(), avatar_action::eat(), empty_buckets(), computer_session::failure_destroy_blood(), computer_session::failure_destroy_data(), fill_with(), final_info(), character_funcs::find_ammo_helper(), character_funcs::fmt_wielded_weapon(), get_category(), Character::get_consumable_from(), get_contained(), get_encumber(), get_free_mod_locations(), liquid_handler::get_liquid_target(), get_quality(), get_remaining_capacity_for_liquid(), json_item_substitution::get_substitution(), trading_window::get_var_trade(), goes_bad_after_opening(), gunmods(), liquid_handler::handle_liquid_from_container(), Character::handle_melee_wear(), handle_problematic_pickup(), pickup::handle_spillable_contents(), has_effect_when_carried(), Character::i_add_to_container(), info(), is_ammo_container(), is_container_empty(), is_container_full(), advanced_inv_area::is_container_valid(), is_dangerous(), is_food_container(), is_funnel_container(), is_med_container(), is_reloadable_helper(), item_has_uses_recursive(), Character::item_reload_cost(), magazine_current(), item_location::impl::item_in_container::make_dirty(), Character::melee_special_effects(), Item_factory::migrate_item(), activity_handlers::mind_splicer_finish(), advanced_inventory::move_content(), iuse::multicooker(), needs_processing(), on_pickup(), operator<(), peek_related_recipe(), put_in(), item_reload_option::qty(), qualities_info(), iuse::radiocar(), avatar_action::reload(), bandolier_actor::reload(), reload(), item_contents::remove_internal(), visitable< T >::remove_items_with(), character_funcs::select_ammo(), serialize(), advanced_inv_area::set_container(), map::smash_items(), spill_contents(), spoilage_sort_order(), stacks_with(), tname(), toolmods(), iexamine::tree_maple_tapped(), try_consume(), salvage_actor::try_to_cut_up(), character_funcs::try_wield_contents(), avatar_funcs::unload_item(), item_location::impl::item_in_container::unpack(), holster_actor::use(), bandolier_actor::use(), salvage_actor::valid_to_cut_up(), visit_internal(), volume(), iuse::water_purifier(), weight(), avatar::wield(), avatar_action::wield(), npc::wield_better_weapon(), and memorial_logger::write().

◆ corpse

◆ corpse_name

std::string item::corpse_name
private

Definition at line 2173 of file item.h.

Referenced by get_corpse_name(), io(), and type_name().

◆ craft_data_

◆ curammo

const itype* item::curammo = nullptr
private

Definition at line 2170 of file item.h.

Referenced by ammo_consume(), ammo_data(), ammo_set(), ammo_unset(), gun_info(), io(), and reload().

◆ damage_

int item::damage_ = 0
private

Definition at line 2232 of file item.h.

Referenced by basic_info(), damage(), damage_level(), io(), mod_damage(), on_damage(), set_damage(), and stacks_with().

◆ drop_token

pimpl<item_drop_token> item::drop_token

Two items are dropped in same "batch" if they have identical drop tokens Ideally, this would be stored outside item class.

Definition at line 2250 of file item.h.

Referenced by pickup::obtain_and_tokenize_items(), and pickup::optimize_pickup().

◆ encumbrance_update_

bool item::encumbrance_update_ = false

Definition at line 2215 of file item.h.

Referenced by on_contents_changed().

◆ energy

units::energy item::energy

Definition at line 2200 of file item.h.

Referenced by energy_remaining(), io(), mod_energy(), and process_tool().

◆ faults

◆ frequency

int item::frequency = 0

Definition at line 2205 of file item.h.

Referenced by io(), and iuse::radio_on().

◆ INFINITE_CHARGES

◆ invlet

◆ irradiation

int item::irradiation = 0

Definition at line 2207 of file item.h.

Referenced by armor_fit_info(), and io().

◆ is_favorite

◆ item_counter

◆ item_tags

◆ item_vars

std::map<std::string, std::string> item::item_vars
private

◆ last_rot_check

time_point item::last_rot_check = calendar::turn_zero
private

Time when the rot calculation was last performed.

Definition at line 2225 of file item.h.

Referenced by basic_info(), calc_rot(), io(), item(), legacy_fast_forward_time(), mod_last_rot_check(), process(), process_rot(), and set_relative_rot().

◆ light

light_emission item::light = nolight
private

Definition at line 2233 of file item.h.

Referenced by getlight(), io(), and is_emissive().

◆ mission_id

int item::mission_id = -1

◆ old_owner

faction_id item::old_owner = faction_id::NULL_ID()
mutableprivate

◆ owner

◆ player_id

int item::player_id = -1

Definition at line 2210 of file item.h.

Referenced by mission::deserialize(), io(), and mission::serialize().

◆ poison

◆ recipe_charges

int item::recipe_charges = 1

Definition at line 2202 of file item.h.

Referenced by complete_craft(), Character::compute_effective_nutrients(), and io().

◆ relic_data

◆ rot

time_duration item::rot = 0_turns
private

Accumulated rot, expressed as time the item has been in standard temperature.

It is compared to shelf life (islot_comestible::spoils) to decide if the item is rotten.

Definition at line 2223 of file item.h.

Referenced by basic_info(), minimum_freshness_duration(), spoilage_sort_order(), and stacks_with().

◆ snip_id

snippet_id item::snip_id = snippet_id::NULL_ID()

Definition at line 2206 of file item.h.

Referenced by basic_info(), io(), item(), and set_snippet().

◆ techniques

std::set<matec_id> item::techniques
private

Definition at line 2174 of file item.h.

Referenced by add_technique(), combat_info(), get_techniques(), has_technique(), io(), and stacks_with().

◆ type

const itype* item::type

Definition at line 2160 of file item.h.

Referenced by activate(), npc::activate_item(), actualize_rot(), game::add_artifact_dreams(), map::add_item(), add_monsters(), iuse::adrenaline_injector(), alcohol(), ammo_capacity(), ammo_data(), ammo_default(), ammo_effects(), ammo_required(), ammo_set(), ammo_type(), ammo_types(), iuse::antiasthmatic(), iuse::antibiotic(), iuse::anticonvulsant(), iuse::antifungal(), iuse::antiparasitic(), apply_lock_picking_tool(), armor_info(), armor_protection_info(), iuse::artifact(), iexamine::autodoc(), base_damage_thrown(), base_volume(), basic_info(), battery_info(), iuse::bell(), bionic_info(), talk_function::bionic_install(), iuse::blech(), iuse::blech_because_unclean(), iuse::blood_draw(), iuse::boltcutters(), book_info(), brewing_results(), brewing_time(), mdeath::broken(), burn(), Character::burn_fuel(), iuse::c4(), character_effects::calc_focus_equilibrium(), iuse::call_of_tindalos(), iuse::camera(), item_funcs::can_be_unloaded(), can_contain(), can_do_activity_there(), Character::can_eat(), iuse::can_goo(), can_holster(), npc::can_read(), Character::can_reload(), bandolier_actor::can_store(), fireweapon_off_actor::can_use(), manualnoise_actor::can_use(), install_bionic_actor::can_use(), saw_barrel_actor::can_use_on(), saw_stock_actor::can_use_on(), iuse::capture_monster_act(), charges_per_volume(), check_art_charge_req(), iuse::chew(), iuse::chop_logs(), chop_plank_activity(), iuse::chop_tree(), chop_tree_activity(), iuse::clear_rubble(), color(), color_in_inventory(), combat_info(), common_ammo_default(), prepared_item_consumption::consume(), Character::consume_effects(), Character::consume_med(), iuse::contacts(), contain_monster(), container_info(), convert(), count_by_charges(), activity_handlers::cracking_do_turn(), Character::crit_chance(), iuse::crowbar(), damage_melee(), iuse::datura(), deactivate(), deserialize(), mission::deserialize(), player_morale::morale_point::deserialize(), addiction::deserialize(), vehicle::deserialize(), detonate(), iuse::dig(), iuse::dig_channel(), iuse::directional_antenna(), iuse::directional_hologram(), display_name(), iuse::dive_tank(), avatar::do_read(), iuse::dog_whistle(), game::dump_stats(), Character::eat(), mattack::eat_food(), iuse::ecig(), iuse::ehandcuffs(), iuse::einktabletpc(), emit_radio_signal(), engine_displacement(), Character::enumerate_unmet_requirements(), iuse::extinguisher(), iuse::eyedrops(), faults_potential(), talk_function::field_harvest(), iuse::fill_pit(), final_info(), find_armor_data(), find_best_lock_picking_tool(), npc::find_dangerous_explosives(), npc::finish_read(), heal_actor::finish_using(), avatar_action::fire_wielded_weapon(), iuse::firecracker(), iexamine::fireplace(), iuse::flumed(), iuse::flusleep(), iuse::foodperson(), fuel_energy(), fuel_pump_terrain(), iuse::fungicide(), iuse::gasmask(), iuse::geiger(), json_talk_topic::gen_responses(), Character::get_acquirable_energy(), activatable_inventory_preset::get_action_name(), bionic_install_preset::get_anesth_amount(), bionic_uninstall_preset::get_anesth_amount(), get_available_recipes(), get_base_env_resist(), get_base_env_resist_w_filter(), read_inventory_preset::get_book(), character_funcs::get_book_fun_for(), avatar::get_book_reader(), get_category(), get_chapters(), get_clothing_mod_val(), get_comestible(), get_comestible_fun(), get_container_capacity(), activatable_inventory_preset::get_denial(), read_inventory_preset::get_denial(), bionic_install_preset::get_denial(), bionic_install_surgeon_preset::get_denial(), bionic_uninstall_preset::get_denial(), comestible_inventory_preset::get_edible_comestible(), get_encumber_when_containing(), get_env_resist(), bionic_install_preset::get_failure_chance(), bionic_install_surgeon_preset::get_failure_chance(), bionic_uninstall_preset::get_failure_chance(), ranged::get_fastest_sight(), get_gun_ups_drain(), npc::get_healing_item(), Character::get_hit_weapon(), get_layer(), get_min_str(), get_mod_locations(), ranged::get_most_accurate_sight(), zone_manager::get_near_zone_type_for_item(), bionic_install_preset::get_operation_duration(), bionic_install_surgeon_preset::get_operation_duration(), bionic_uninstall_preset::get_operation_duration(), comestible_inventory_preset::get_order(), get_pet_armor_bodytype(), get_pet_armor_max_vol(), get_pet_armor_min_vol(), get_plant_epoch(), get_plant_name(), get_property_int64_t(), get_property_string(), get_qualities(), get_quality(), get_reload_time(), get_remaining_capacity_for_liquid(), get_storage(), get_techniques(), get_thickness(), get_total_capacity(), get_use_internal(), plot_options::get_zone_name_suggestion(), getGasDiscountCardQuality(), getlight_emit(), goes_bad_after_opening(), iuse::granade(), iuse::granade_act(), gun_damage(), gun_dispersion(), gun_info(), gun_noise(), gun_range(), gun_recoil(), gun_recoil_multiplier(), iuse::gun_repair(), gun_skill(), npc_ai::gun_value(), gunmod_info(), avatar_funcs::gunmod_installation_odds(), iuse::hacksaw(), iuse::hairkit(), iuse::hammer(), iuse::handle_ground_graffiti(), ranged::handle_gun_damage(), has_effect_when_carried(), has_effect_when_wielded(), has_effect_when_worn(), has_explosion_data(), has_flag(), npc::has_healing_options(), has_property(), has_technique(), has_use(), npc::heal_player(), npc::heal_self(), iuse::honeycomb(), in_its_container(), countdown_actor::info(), info(), iuse::inhaler(), inherit_flags(), Character::invoke_item(), avatar::invoke_item(), npc::invoke_item(), io(), is_ammo(), is_artifact(), is_bandolier(), is_battery(), is_bionic(), is_book(), is_brewable(), is_bucket(), is_container(), is_deployable(), is_emissive(), is_engine(), is_fuel(), is_gun(), is_gunmod(), is_holster(), is_magazine(), is_non_resealable_container(), is_null(), avatar_funcs::is_pet_food(), is_seed(), activatable_inventory_preset::is_shown(), is_tool(), is_toolmod(), is_transformable(), is_upgrade(), is_watertight_container(), is_wheel(), item(), item_has_uses_recursive(), Character::item_reload_cost(), item_reload_option::item_reload_option(), iuse::jackhammer(), iuse::jet_injector(), submap::load(), iuse::lumber(), iuse::ma_manual(), made_of(), magazine_compatible(), magazine_default(), magazine_info(), magazine_integral(), iuse::makemound(), mark_chapter_as_read(), iuse::marloss(), iuse::marloss_gel(), iuse::marloss_seed(), max_damage(), iuse::meditate(), Character::meets_requirements(), Character::meets_stat_requirements(), iuse::melatonin_tablet(), npc_ai::melee_value(), iuse::meth(), mill_load_food(), min_damage(), iuse::mind_splicer(), mine_activity(), minimum_freshness_duration(), iuse::mininuke(), mod_damage(), mod_energy(), Item_modifier::modify(), iuse::modify_grid_connections(), Character::modify_morale(), iuse::mop(), avatar_action::move(), iuse::mp3(), iuse::mp3_on(), iuse::multicooker(), mutagen_common_checks(), iuse::mycus(), iuse::noise_emitter_off(), iuse::noise_emitter_on(), on_contents_changed(), on_drop(), on_pickup(), on_takeoff(), on_wear(), on_wield(), operator<(), iuse::oxygen_bottle(), iuse::pheromone(), iuse::plantblech(), iuse::poison(), iuse::portal(), Character::pour_into(), price(), process(), game::process_artifact(), process_cable(), process_extinguish(), process_internal(), Character::process_items(), process_tool(), process_vehicle_items(), process_wet(), vehicle_part::properties_to_item(), iuse::prozac(), iuse::purifier(), iuse::purify_iv(), iuse::purify_smart(), item_reload_option::qty(), qualities_info(), quality_of(), plot_options::query_seed(), iuse::radglove(), iuse::radio_off(), iuse::radio_on(), iuse::radiocar(), iuse::radiocaron(), iuse::radiocontrol(), examine_item_menu::rate_action_use(), rate_food(), read(), avatar::read(), read_inventory_preset::read_inventory_preset(), avatar_action::reload(), reload(), activity_handlers::reload_finish(), iuse::remoteveh(), repair_item_actor::repair_recipe_difficulty(), repaired_with(), reset_cable(), mattack::riotbot(), iuse::rm13armor_off(), iuse::rm13armor_on(), iuse::robotcontrol(), iexamine::safe(), iuse::seed(), mission::serialize(), player_morale::morale_point::serialize(), addiction::serialize(), vehicle::serialize(), iuse::sewage(), iuse::shavekit(), activity_handlers::shear_finish(), iuse::shocktonfa_off(), sight_dispersion(), simulate_burn(), iuse::siphon(), skim_book_msg(), iuse::sleep(), smoker_activate(), iuse::smoking(), activity_handlers::spellcasting_finish(), spoilage_sort_order(), stacks_with(), activity_handlers::start_fire_do_turn(), activity_handlers::start_fire_finish(), npc::start_read(), iuse::stimpack(), iuse::strong_antibiotic(), symbol(), iuse::talking_doll(), iuse::tazer(), iuse::teleport(), iuse::thorazine(), ranged::throw_item(), ranged::time_to_attack(), npc::time_to_read(), avatar::time_to_read(), tname(), iuse::toolmod_attach(), toolweapon_off(), toolweapon_on(), iuse::towel_common(), try_consume(), type_name(), typeId(), avatar_funcs::unload_item(), target_ui::update_ammo_range_from_gun_mode(), update_clothing_mod_val(), charger_tile::update_internal(), iuse_transform::use(), countdown_actor::use(), consume_drug_iuse::use(), pick_lock_actor::use(), firestarter_actor::use(), fireweapon_off_actor::use(), fireweapon_on_actor::use(), manualnoise_actor::use(), heal_actor::use(), mutagen_actor::use(), mutagen_iv_actor::use(), install_bionic_actor::use(), avatar_funcs::use_item(), vehicle::use_monster_capture(), iuse::vaccine(), npc::value(), iuse::vibe(), volume(), iuse::vortex(), iuse::weak_antibiotic(), npc_ai::weapon_value(), iuse::weed_cake(), weight(), wheel_area(), vehicle_part::wheel_diameter(), vehicle_part::wheel_width(), npc::wield_better_weapon(), npc_ai::wielded_value(), npc::will_accept_from_player(), will_explode_in_fire(), and iuse::xanax().


The documentation for this class was generated from the following files: